repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppModule.java
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java // @Singleton // public class AppViewModelFactory implements ViewModelFactory { // // @Inject // AppViewModelFactory() { // // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new MainViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new ClickCountViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new AndroidVersionsViewModel(adapter, activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // return new AndroidVersionItemViewModel(activityComponent); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.sample.mvvm.viewmodel.AppViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class SampleAppModule { @Provides @Singleton
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java // @Singleton // public class AppViewModelFactory implements ViewModelFactory { // // @Inject // AppViewModelFactory() { // // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new MainViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new ClickCountViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new AndroidVersionsViewModel(adapter, activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // return new AndroidVersionItemViewModel(activityComponent); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppModule.java import com.hibrianlee.sample.mvvm.viewmodel.AppViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class SampleAppModule { @Provides @Singleton
ViewModelFactory provideViewModelFactory(AppViewModelFactory appViewModelFactory) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppModule.java
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java // @Singleton // public class AppViewModelFactory implements ViewModelFactory { // // @Inject // AppViewModelFactory() { // // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new MainViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new ClickCountViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new AndroidVersionsViewModel(adapter, activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // return new AndroidVersionItemViewModel(activityComponent); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.sample.mvvm.viewmodel.AppViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class SampleAppModule { @Provides @Singleton
// Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/AppViewModelFactory.java // @Singleton // public class AppViewModelFactory implements ViewModelFactory { // // @Inject // AppViewModelFactory() { // // } // // @NonNull // @Override // public MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new MainViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public ClickCountViewModel createClickCountViewModel( // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new ClickCountViewModel(activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState) { // return new AndroidVersionsViewModel(adapter, activityComponent, savedViewModelState); // } // // @NonNull // @Override // public AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent) { // return new AndroidVersionItemViewModel(activityComponent); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppModule.java import com.hibrianlee.sample.mvvm.viewmodel.AppViewModelFactory; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Singleton; import dagger.Module; import dagger.Provides; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Module public class SampleAppModule { @Provides @Singleton
ViewModelFactory provideViewModelFactory(AppViewModelFactory appViewModelFactory) {
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // }
import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import dagger.Module; import dagger.Provides;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; @Module public final class ActivityModule {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityModule.java import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import dagger.Module; import dagger.Provides; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; @Module public final class ActivityModule {
private final ViewModelActivity activity;
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // }
import android.content.Context; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; public interface AppComponent { @AppContext Context appContext();
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java import android.content.Context; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; public interface AppComponent { @AppContext Context appContext();
void inject(ViewModelActivity viewModelActivity);
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // }
import android.content.Context; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; public interface AppComponent { @AppContext Context appContext(); void inject(ViewModelActivity viewModelActivity);
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/fragment/ViewModelFragment.java // public abstract class ViewModelFragment extends Fragment { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Nullable // protected abstract ViewModel createAndBindViewModel(View root, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @Override // public void onCreate(@Nullable Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // AppComponent appComponent = // ((MvvmApplication) getActivity().getApplication()).getAppComponent(); // inject(appComponent); // } // // @Override // public void onActivityCreated(@Nullable Bundle savedInstanceState) { // super.onActivityCreated(savedInstanceState); // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // ViewModelActivity activity = (ViewModelActivity) getActivity(); // viewModel = createAndBindViewModel(getView(), activity.getActivityComponent(), // savedViewModelState); // } // // @Override // public void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // public void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // public void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java import android.content.Context; import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.fragment.ViewModelFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; public interface AppComponent { @AppContext Context appContext(); void inject(ViewModelActivity viewModelActivity);
void inject(ViewModelFragment viewModelFragment);
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModel.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import android.databinding.Bindable; import android.os.Parcel; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.R;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountViewModel extends ViewModel { int clicks;
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModel.java import android.databinding.Bindable; import android.os.Parcel; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.inject.ActivityComponent; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.BR; import com.hibrianlee.sample.mvvm.R; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.viewmodel; public class ClickCountViewModel extends ViewModel { int clicks;
ClickCountViewModel(@NonNull ActivityComponent activityComponent,
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject
protected ViewModelFactory viewModelFactory;
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject protected ViewModelFactory viewModelFactory; @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject protected ViewModelFactory viewModelFactory; @Override
protected void inject(AppComponent appComponent) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // }
import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject protected ViewModelFactory viewModelFactory; @Override protected void inject(AppComponent appComponent) {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/activity/ViewModelActivity.java // public abstract class ViewModelActivity extends AppCompatActivity { // // private static final String EXTRA_VIEW_MODEL_STATE = "viewModelState"; // // private ActivityComponent activityComponent; // private ViewModel viewModel; // // protected void inject(AppComponent appComponent) { // appComponent.inject(this); // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // // AppComponent appComponent = ((MvvmApplication) getApplication()).getAppComponent(); // inject(appComponent); // // activityComponent = DaggerActivityComponent.builder() // .appComponent(appComponent) // .activityModule(new ActivityModule(this)) // .build(); // // ViewModel.State savedViewModelState = null; // if (savedInstanceState != null) { // savedViewModelState = savedInstanceState.getParcelable(EXTRA_VIEW_MODEL_STATE); // } // viewModel = createViewModel(savedViewModelState); // } // // @Nullable // protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) { // return null; // } // // @Override // protected void onStart() { // super.onStart(); // if (viewModel != null) { // viewModel.onStart(); // } // } // // @Override // protected void onSaveInstanceState(Bundle outState) { // super.onSaveInstanceState(outState); // if (viewModel != null) { // outState.putParcelable(EXTRA_VIEW_MODEL_STATE, viewModel.getInstanceState()); // } // } // // @Override // protected void onStop() { // super.onStop(); // if (viewModel != null) { // viewModel.onStop(); // } // } // // public final ActivityComponent getActivityComponent() { // return activityComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java // @Singleton // @Component(modules = { // AppContextModule.class, // SampleAppModule.class // }) // public interface SampleAppComponent extends AppComponent { // // void inject(BaseActivity baseActivity); // // void inject(BaseFragment baseFragment); // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ViewModelFactory.java // public interface ViewModelFactory { // // @NonNull // MainViewModel createMainViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // @NonNull // ClickCountViewModel createClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionsViewModel createAndroidVersionsViewModel( // @NonNull AndroidVersionsAdapter adapter, // @NonNull ActivityComponent activityComponent, // @Nullable ViewModel.State savedViewModelState); // // @NonNull // AndroidVersionItemViewModel createAndroidVersionItemViewModel( // @NonNull ActivityComponent activityComponent); // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java import com.hibrianlee.mvvmapp.activity.ViewModelActivity; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.sample.mvvm.SampleAppComponent; import com.hibrianlee.sample.mvvm.viewmodel.ViewModelFactory; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class BaseActivity extends ViewModelActivity { @Inject protected ViewModelFactory viewModelFactory; @Override protected void inject(AppComponent appComponent) {
((SampleAppComponent) appComponent).inject(this);
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/BaseTest.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // }
import android.content.Context; import android.support.annotation.CallSuper; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import junit.framework.Assert; import org.junit.Before; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import javax.inject.Inject;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class BaseTest extends Assert { protected final TestComponent testComponent; @Inject @AppContext protected Context appContext; @Inject
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AttachedActivity.java // public interface AttachedActivity { // // void startActivity(Class<? extends Activity> activityClass); // // void openUrl(String url) throws URISyntaxException; // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/BaseTest.java import android.content.Context; import android.support.annotation.CallSuper; import com.hibrianlee.mvvmapp.inject.AppContext; import com.hibrianlee.mvvmapp.inject.AttachedActivity; import junit.framework.Assert; import org.junit.Before; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import javax.inject.Inject; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class BaseTest extends Assert { protected final TestComponent testComponent; @Inject @AppContext protected Context appContext; @Inject
protected AttachedActivity attachedActivity;
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // }
import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {
AppContextModule.class,
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // }
import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class })
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class })
public interface SampleAppComponent extends AppComponent {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // }
import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class }) public interface SampleAppComponent extends AppComponent {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class }) public interface SampleAppComponent extends AppComponent {
void inject(BaseActivity baseActivity);
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // }
import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class }) public interface SampleAppComponent extends AppComponent { void inject(BaseActivity baseActivity);
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/BaseActivity.java // public class BaseActivity extends ViewModelActivity { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/fragment/BaseFragment.java // public abstract class BaseFragment extends ViewModelFragment { // // @Inject // protected ViewModelFactory viewModelFactory; // // @Override // protected void inject(AppComponent appComponent) { // ((SampleAppComponent) appComponent).inject(this); // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/SampleAppComponent.java import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; import com.hibrianlee.sample.mvvm.activity.BaseActivity; import com.hibrianlee.sample.mvvm.fragment.BaseFragment; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = { AppContextModule.class, SampleAppModule.class }) public interface SampleAppComponent extends AppComponent { void inject(BaseActivity baseActivity);
void inject(BaseFragment baseFragment);
hiBrianLee/AndroidMvvm
sample/src/test/java/com/hibrianlee/sample/mvvm/TestComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // }
import com.hibrianlee.mvvmapp.inject.ActivityComponent; import javax.inject.Singleton; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {TestModule.class})
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java // @PerActivity // @Component( // dependencies = AppComponent.class, // modules = {ActivityModule.class}) // public interface ActivityComponent { // // void inject(ViewModel viewModel); // } // Path: sample/src/test/java/com/hibrianlee/sample/mvvm/TestComponent.java import com.hibrianlee.mvvmapp.inject.ActivityComponent; import javax.inject.Singleton; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; @Singleton @Component(modules = {TestModule.class})
public interface TestComponent extends ActivityComponent {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModel.java // public class ClickCountViewModel extends ViewModel { // // int clicks; // // ClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // super(activityComponent, savedInstanceState); // if (savedInstanceState instanceof ClickCountState) { // clicks = ((ClickCountState) savedInstanceState).clicks; // } // } // // @Override // public State getInstanceState() { // return new ClickCountState(this); // } // // @Bindable // public String getClickCountText() { // return String.format(appContext.getString(R.string.click_count), clicks); // } // // public void onClickButton() { // clicks++; // notifyPropertyChanged(BR.clickCountText); // } // // public void onClickHiBrianLee() { // try { // attachedActivity.openUrl(appContext.getString(R.string.twitter_url)); // } catch (Exception e) { // e.printStackTrace(); // } // } // // private static class ClickCountState extends State { // // private final int clicks; // // protected ClickCountState(ClickCountViewModel viewModel) { // super(viewModel); // clicks = viewModel.clicks; // } // // public ClickCountState(Parcel in) { // super(in); // clicks = in.readInt(); // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // super.writeToParcel(dest, flags); // dest.writeInt(clicks); // } // // public static Creator<ClickCountState> CREATOR = new Creator<ClickCountState>() { // @Override // public ClickCountState createFromParcel(Parcel source) { // return new ClickCountState(source); // } // // @Override // public ClickCountState[] newArray(int size) { // return new ClickCountState[size]; // } // }; // } // }
import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.databinding.ActivityClickCountBinding; import com.hibrianlee.sample.mvvm.viewmodel.ClickCountViewModel; import butterknife.ButterKnife; import butterknife.OnClick;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class ClickCountActivity extends BaseActivity { private ClickCountViewModel clickCountViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityClickCountBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_click_count); binding.setViewModel(clickCountViewModel); ButterKnife.bind(this); } @Nullable @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/viewmodel/ClickCountViewModel.java // public class ClickCountViewModel extends ViewModel { // // int clicks; // // ClickCountViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // super(activityComponent, savedInstanceState); // if (savedInstanceState instanceof ClickCountState) { // clicks = ((ClickCountState) savedInstanceState).clicks; // } // } // // @Override // public State getInstanceState() { // return new ClickCountState(this); // } // // @Bindable // public String getClickCountText() { // return String.format(appContext.getString(R.string.click_count), clicks); // } // // public void onClickButton() { // clicks++; // notifyPropertyChanged(BR.clickCountText); // } // // public void onClickHiBrianLee() { // try { // attachedActivity.openUrl(appContext.getString(R.string.twitter_url)); // } catch (Exception e) { // e.printStackTrace(); // } // } // // private static class ClickCountState extends State { // // private final int clicks; // // protected ClickCountState(ClickCountViewModel viewModel) { // super(viewModel); // clicks = viewModel.clicks; // } // // public ClickCountState(Parcel in) { // super(in); // clicks = in.readInt(); // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // super.writeToParcel(dest, flags); // dest.writeInt(clicks); // } // // public static Creator<ClickCountState> CREATOR = new Creator<ClickCountState>() { // @Override // public ClickCountState createFromParcel(Parcel source) { // return new ClickCountState(source); // } // // @Override // public ClickCountState[] newArray(int size) { // return new ClickCountState[size]; // } // }; // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/activity/ClickCountActivity.java import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.annotation.Nullable; import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import com.hibrianlee.sample.mvvm.R; import com.hibrianlee.sample.mvvm.databinding.ActivityClickCountBinding; import com.hibrianlee.sample.mvvm.viewmodel.ClickCountViewModel; import butterknife.ButterKnife; import butterknife.OnClick; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm.activity; public class ClickCountActivity extends BaseActivity { private ClickCountViewModel clickCountViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityClickCountBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_click_count); binding.setViewModel(clickCountViewModel); ButterKnife.bind(this); } @Nullable @Override
protected ViewModel createViewModel(@Nullable ViewModel.State savedViewModelState) {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/MvvmSampleApplication.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // }
import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class MvvmSampleApplication extends MvvmApplication { @Override
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/MvvmSampleApplication.java import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class MvvmSampleApplication extends MvvmApplication { @Override
protected AppComponent createAppComponent() {
hiBrianLee/AndroidMvvm
sample/src/main/java/com/hibrianlee/sample/mvvm/MvvmSampleApplication.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // }
import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class MvvmSampleApplication extends MvvmApplication { @Override protected AppComponent createAppComponent() { return DaggerSampleAppComponent.builder()
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/MvvmApplication.java // public abstract class MvvmApplication extends Application { // // private AppComponent appComponent; // // protected abstract AppComponent createAppComponent(); // // @Override // public void onCreate() { // super.onCreate(); // // if (appComponent == null) { // appComponent = createAppComponent(); // } // } // // public AppComponent getAppComponent() { // return appComponent; // } // // public void setAppComponent(AppComponent appComponent) { // this.appComponent = appComponent; // } // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppComponent.java // public interface AppComponent { // // @AppContext // Context appContext(); // // void inject(ViewModelActivity viewModelActivity); // // void inject(ViewModelFragment viewModelFragment); // } // // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/AppContextModule.java // @Module // public class AppContextModule { // // private final Context appContext; // // public AppContextModule(Application application) { // appContext = application; // } // // @Provides // @Singleton // @AppContext // Context provideAppContext() { // return appContext; // } // } // Path: sample/src/main/java/com/hibrianlee/sample/mvvm/MvvmSampleApplication.java import com.hibrianlee.mvvmapp.MvvmApplication; import com.hibrianlee.mvvmapp.inject.AppComponent; import com.hibrianlee.mvvmapp.inject.AppContextModule; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.sample.mvvm; public class MvvmSampleApplication extends MvvmApplication { @Override protected AppComponent createAppComponent() { return DaggerSampleAppComponent.builder()
.appContextModule(new AppContextModule(this))
hiBrianLee/AndroidMvvm
mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // }
import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import dagger.Component;
/* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; @PerActivity @Component( dependencies = AppComponent.class, modules = {ActivityModule.class}) public interface ActivityComponent {
// Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/viewmodel/ViewModel.java // public abstract class ViewModel extends BaseObservable { // // @Inject // @AppContext // protected Context appContext; // // @Inject // protected AttachedActivity attachedActivity; // // protected ViewModel(@NonNull ActivityComponent activityComponent, // @Nullable State savedInstanceState) { // activityComponent.inject(this); // } // // @CallSuper // public void onStart() { // // } // // public State getInstanceState() { // return new State(this); // } // // @CallSuper // public void onStop() { // // } // // public static class State implements Parcelable { // // protected State(ViewModel viewModel) { // // } // // public State(Parcel in) { // // } // // @Override // public int describeContents() { // return 0; // } // // @CallSuper // @Override // public void writeToParcel(Parcel dest, int flags) { // // } // // public static Creator<State> CREATOR = new Creator<State>() { // @Override // public State createFromParcel(Parcel source) { // return new State(source); // } // // @Override // public State[] newArray(int size) { // return new State[size]; // } // }; // } // } // Path: mvvmapp/src/main/java/com/hibrianlee/mvvmapp/inject/ActivityComponent.java import com.hibrianlee.mvvmapp.viewmodel.ViewModel; import dagger.Component; /* * Copyright (C) 2015 Brian Lee (@hiBrianLee) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hibrianlee.mvvmapp.inject; @PerActivity @Component( dependencies = AppComponent.class, modules = {ActivityModule.class}) public interface ActivityComponent {
void inject(ViewModel viewModel);
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCAS1Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCAS1Block extends InterpretedBlock { public ByteString mIdentifier; public ByteString mVersionNumber;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCAS1Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCAS1Block extends InterpretedBlock { public ByteString mIdentifier; public ByteString mVersionNumber;
public RKFInteger mSectorStatus0;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBStaticBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDBStaticBlock extends InterpretedBlock { public ByteString mIdentifier;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBStaticBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDBStaticBlock extends InterpretedBlock { public ByteString mIdentifier;
public RKFInteger mVersionNumber;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBStaticBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDBStaticBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public ByteString mAID; public RKFInteger mDiscountType1; public RKFInteger mDiscountType2; public RKFInteger mDiscountType3; public ByteString mFree; public TCDBStaticBlock(byte[] bits) { super("TCDBStatic", bits); mIdentifier = new ByteString(8, false); mVersionNumber = new RKFInteger(6, true); mAID = new ByteString(12, true); mDiscountType1 = new RKFInteger(8, true); mDiscountType2 = new RKFInteger(8, true); mDiscountType3 = new RKFInteger(8, true); mFree = new ByteString(78, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBStaticBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDBStaticBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public ByteString mAID; public RKFInteger mDiscountType1; public RKFInteger mDiscountType2; public RKFInteger mDiscountType3; public ByteString mFree; public TCDBStaticBlock(byte[] bits) { super("TCDBStatic", bits); mIdentifier = new ByteString(8, false); mVersionNumber = new RKFInteger(6, true); mAID = new ByteString(12, true); mDiscountType1 = new RKFInteger(8, true); mDiscountType2 = new RKFInteger(8, true); mDiscountType3 = new RKFInteger(8, true); mFree = new ByteString(78, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI1Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDI1Block extends InterpretedBlock { public ByteString mAIDPIX1; public ByteString mAIDPIX2; public ByteString mAIDPIX3; public ByteString mAIDPIX4; public ByteString mAIDPIX5; public ByteString mChecksum; public TCDI1Block(byte[] bits) { super("TCDI1", bits); mAIDPIX1 = new ByteString(24, true); mAIDPIX2 = new ByteString(24, true); mAIDPIX3 = new ByteString(24, true); mAIDPIX4 = new ByteString(24, true); mAIDPIX5 = new ByteString(24, true); mChecksum = new ByteString(8, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI1Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDI1Block extends InterpretedBlock { public ByteString mAIDPIX1; public ByteString mAIDPIX2; public ByteString mAIDPIX3; public ByteString mAIDPIX4; public ByteString mAIDPIX5; public ByteString mChecksum; public TCDI1Block(byte[] bits) { super("TCDI1", bits); mAIDPIX1 = new ByteString(24, true); mAIDPIX2 = new ByteString(24, true); mAIDPIX3 = new ByteString(24, true); mAIDPIX4 = new ByteString(24, true); mAIDPIX5 = new ByteString(24, true); mChecksum = new ByteString(8, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CommonTCSTBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class CommonTCSTBlock extends InterpretedBlock { public ByteString mIdentifier;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CommonTCSTBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class CommonTCSTBlock extends InterpretedBlock { public ByteString mIdentifier;
public RKFInteger mVersionNumber;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CommonTCSTBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class CommonTCSTBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public CommonTCSTBlock(byte[] bits) { super("CommonTCST", bits); mIdentifier = new ByteString(8, false); mVersionNumber = new RKFInteger(6, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CommonTCSTBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class CommonTCSTBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public CommonTCSTBlock(byte[] bits) { super("CommonTCST", bits); mIdentifier = new ByteString(8, false); mVersionNumber = new RKFInteger(6, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI2Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDI2Block extends InterpretedBlock { public ByteString mAIDPIX6; public ByteString mAIDPIX7; public ByteString mAIDPIX8; public ByteString mAIDPIX9; public ByteString mAIDPIX10; public ByteString mChecksum; public TCDI2Block(byte[] bits) { super("TCDI2", bits); mAIDPIX6 = new ByteString(24, true); mAIDPIX7 = new ByteString(24, true); mAIDPIX8 = new ByteString(24, true); mAIDPIX9 = new ByteString(24, true); mAIDPIX10 = new ByteString(24, true); mChecksum = new ByteString(8, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI2Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDI2Block extends InterpretedBlock { public ByteString mAIDPIX6; public ByteString mAIDPIX7; public ByteString mAIDPIX8; public ByteString mAIDPIX9; public ByteString mAIDPIX10; public ByteString mChecksum; public TCDI2Block(byte[] bits) { super("TCDI2", bits); mAIDPIX6 = new ByteString(24, true); mAIDPIX7 = new ByteString(24, true); mAIDPIX8 = new ByteString(24, true); mAIDPIX9 = new ByteString(24, true); mAIDPIX10 = new ByteString(24, true); mChecksum = new ByteString(8, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCSTv4Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateTime.java // public class DateTime extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); // // public DateTime(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MINUTE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return "Date " + getDate(); // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateTime;
package info.rejsekort.reader.rkf.blocks; public class TCSTv4Block extends info.rejsekort.reader.rkf.TCSTBlock { public ByteString mIdentifier;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateTime.java // public class DateTime extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); // // public DateTime(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MINUTE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return "Date " + getDate(); // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCSTv4Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateTime; package info.rejsekort.reader.rkf.blocks; public class TCSTv4Block extends info.rejsekort.reader.rkf.TCSTBlock { public ByteString mIdentifier;
public RKFInteger mVersionNumber;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCIBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateCompact.java // public class DateCompact extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(97, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateCompact(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.DATE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "Date " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.DateCompact; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCCIBlock extends InterpretedBlock { public ByteString mMADInfoByte;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateCompact.java // public class DateCompact extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(97, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateCompact(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.DATE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "Date " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCIBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.DateCompact; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCCIBlock extends InterpretedBlock { public ByteString mMADInfoByte;
public RKFInteger mCardVersion;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCIBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateCompact.java // public class DateCompact extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(97, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateCompact(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.DATE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "Date " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.DateCompact; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCCIBlock extends InterpretedBlock { public ByteString mMADInfoByte; public RKFInteger mCardVersion; public ByteString mCardProvider;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateCompact.java // public class DateCompact extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(97, 0, 1); // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateCompact(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.DATE, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "Date " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCIBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.DateCompact; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCCIBlock extends InterpretedBlock { public ByteString mMADInfoByte; public RKFInteger mCardVersion; public ByteString mCardProvider;
public DateCompact mCardValidityEndDate;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCPStaticBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth11.java // public class DateMonth11 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(0, 0, 1); //1900-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth11(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth11 " + getDate(); // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateMonth11;
package info.rejsekort.reader.rkf.blocks; public class TCCPStaticBlock extends InterpretedBlock { public ByteString mIdentifier;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth11.java // public class DateMonth11 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(0, 0, 1); //1900-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth11(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth11 " + getDate(); // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCPStaticBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateMonth11; package info.rejsekort.reader.rkf.blocks; public class TCCPStaticBlock extends InterpretedBlock { public ByteString mIdentifier;
public RKFInteger mVersionNumber;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCPStaticBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth11.java // public class DateMonth11 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(0, 0, 1); //1900-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth11(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth11 " + getDate(); // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateMonth11;
package info.rejsekort.reader.rkf.blocks; public class TCCPStaticBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public ByteString mAID; public ByteString mStatus; public RKFInteger mCustomerNumber; public ByteString mXXX1; public RKFInteger mSequenceNumber; public ByteString mXXX2;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth11.java // public class DateMonth11 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(0, 0, 1); //1900-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth11(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth11 " + getDate(); // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCCPStaticBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.DateMonth11; package info.rejsekort.reader.rkf.blocks; public class TCCPStaticBlock extends InterpretedBlock { public ByteString mIdentifier; public RKFInteger mVersionNumber; public ByteString mAID; public ByteString mStatus; public RKFInteger mCustomerNumber; public ByteString mXXX1; public RKFInteger mSequenceNumber; public ByteString mXXX2;
public DateMonth11 mBirthday;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI3Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDI3Block extends InterpretedBlock { public ByteString mAIDPIX11; public ByteString mAIDPIX12; public ByteString mAIDPIX13; public ByteString mAIDPIX14; public ByteString mAIDPIX15; public ByteString mChecksum; public TCDI3Block(byte[] bits) { super("TCDI3", bits); mAIDPIX11 = new ByteString(24, true); mAIDPIX12 = new ByteString(24, true); mAIDPIX13 = new ByteString(24, true); mAIDPIX14 = new ByteString(24, true); mAIDPIX15 = new ByteString(24, true); mChecksum = new ByteString(8, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDI3Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDI3Block extends InterpretedBlock { public ByteString mAIDPIX11; public ByteString mAIDPIX12; public ByteString mAIDPIX13; public ByteString mAIDPIX14; public ByteString mAIDPIX15; public ByteString mChecksum; public TCDI3Block(byte[] bits) { super("TCDI3", bits); mAIDPIX11 = new ByteString(24, true); mAIDPIX12 = new ByteString(24, true); mAIDPIX13 = new ByteString(24, true); mAIDPIX14 = new ByteString(24, true); mAIDPIX15 = new ByteString(24, true); mChecksum = new ByteString(8, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv4Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24;
package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv4Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv4Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24; package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv4Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber;
public MoneyAmount24 mValue;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv4Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24;
package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv4Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv4Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24; package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv4Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue;
public ByteString mXXX;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBDynamicBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth8.java // public class DateMonth8 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); //2000-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth8(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth8 " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.DateMonth8; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDBDynamicBlock extends InterpretedBlock { public ByteString mStatus;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth8.java // public class DateMonth8 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); //2000-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth8(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth8 " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBDynamicBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.DateMonth8; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDBDynamicBlock extends InterpretedBlock { public ByteString mStatus;
public DateMonth8 mFirsthMonth;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBDynamicBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth8.java // public class DateMonth8 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); //2000-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth8(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth8 " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.DateMonth8; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class TCDBDynamicBlock extends InterpretedBlock { public ByteString mStatus; public DateMonth8 mFirsthMonth; public ByteString mXXX1;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DateMonth8.java // public class DateMonth8 extends RKFInteger { // public Date mDate; // @SuppressWarnings("deprecation") // public static Date epoch = new Date(100, 0, 1); //2000-01-01 // public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.US); // // public DateMonth8(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // super.interpret(); // // Calendar cal = Calendar.getInstance(); // cal.setTime(epoch); // cal.add(Calendar.MONTH, mInt); // mDate = cal.getTime(); // } // // public String getDate() { // return sdf.format(mDate); // } // // public String toString() { // return super.toString() + " " + "DateMonth8 " + getDate(); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCDBDynamicBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.DateMonth8; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class TCDBDynamicBlock extends InterpretedBlock { public ByteString mStatus; public DateMonth8 mFirsthMonth; public ByteString mXXX1;
public RKFInteger mDiscountStep;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CMIBlock.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString;
package info.rejsekort.reader.rkf.blocks; public class CMIBlock extends InterpretedBlock { public ByteString mCardSerialNumber; public ByteString mCardSerialNumberCheckByte; public ByteString mManufacturerData; public CMIBlock(byte[] bits) { super("CMI", bits); mCardSerialNumber = new ByteString(32, true); mCardSerialNumberCheckByte = new ByteString(8, true); mManufacturerData = new ByteString(88, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/CMIBlock.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.ByteString; package info.rejsekort.reader.rkf.blocks; public class CMIBlock extends InterpretedBlock { public ByteString mCardSerialNumber; public ByteString mCardSerialNumberCheckByte; public ByteString mManufacturerData; public CMIBlock(byte[] bits) { super("CMI", bits); mCardSerialNumber = new ByteString(32, true); mCardSerialNumberCheckByte = new ByteString(8, true); mManufacturerData = new ByteString(88, true);
mFields = new DataType[] {
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24;
package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24; package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber;
public MoneyAmount24 mValue;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24;
package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue;
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24; package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue;
public ByteString mXXX;
mchro/RejsekortReader
code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // }
import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24;
package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue; public ByteString mXXX; public TCPUDynamicv6Block(byte[] bits) { super("TCPUDynamicv6", bits); mPurseTransactionNumber = new RKFInteger(16, true); mValue = new MoneyAmount24(24, true); mXXX = new ByteString(216, true);
// Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/DataType.java // public abstract class DataType { // /** The bits as a string of "0" and "1": "000110001..." */ // protected String mBits; // protected boolean mReverse = true; // public int mBitlength; // // public DataType(int bitlength, boolean reverse) { // mReverse = reverse; // mBitlength = bitlength; // } // // public void fromBits(String bits) { // mBits = bits; // if (mReverse) { // //reverse the bits // mBits = new StringBuilder(bits).reverse().toString(); // } // interpret(); // } // // abstract void interpret(); // // public static byte[] hexStringToByteArray(String s) { // int len = s.length(); // byte[] data = new byte[len / 2]; // for (int i = 0; i < len; i += 2) { // data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) // + Character.digit(s.charAt(i+1), 16)); // } // return data; // } // // public static String getHexString(byte[] buf) { // StringBuffer sb = new StringBuffer(); // // for (byte b : buf) { // sb.append(String.format("%02x", b)); // } // // return sb.toString(); // } // // public static String getBinaryString(byte[] input){ // StringBuilder sb = new StringBuilder(); // // for (byte c : input) { // for (int n = 128; n > 0; n >>= 1){ // if ((c & n) == 0) // sb.append('0'); // else sb.append('1'); // } // } // // return sb.toString(); // } // // public static byte[] binaryStringToByteArray(String s) { // byte[] ret = new byte[(s.length()+8-1) / 8]; // // BigInteger bigint = new BigInteger(s, 2); // byte[] bigintbytes = bigint.toByteArray(); // // if (bigintbytes.length > ret.length) { // //get rid of preceding 0 // for (int i = 0; i < ret.length; i++) { // ret[i] = bigintbytes[i+1]; // } // } // else { // ret = bigintbytes; // } // return ret; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/RKFInteger.java // public class RKFInteger extends DataType { // public int mInt; // // public RKFInteger(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // BigInteger a = new BigInteger(mBits, 2); // mInt = a.intValue(); // } // // public String toString() { // return "Int " + Integer.toString(mInt); // } // // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/ByteString.java // public class ByteString extends DataType { // public String mString; // // public ByteString(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String revbits = new StringBuffer(mBits).reverse().toString(); // byte[] revbitsarr = binaryStringToByteArray(revbits); // // byte[] bitsarr = new byte[revbitsarr.length]; // for (int i = 0; i < revbitsarr.length; i++) { // bitsarr[revbitsarr.length - i - 1] = revbitsarr[i]; // } // // mString = getHexString(bitsarr); // } // // public String toString() { // return mString; // } // } // // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/datatypes/MoneyAmount24.java // public class MoneyAmount24 extends DataType { // // public String mSign; // public int mAmount; // // public MoneyAmount24(int bitlength, boolean reverse) { // super(bitlength, reverse); // } // // @Override // void interpret() { // String signbit = mBits.substring(0, 1); // if (signbit == "1") // mSign = "-"; // else // mSign = ""; // String amountbits = mBits.substring(1); // // mAmount = new BigInteger(amountbits, 2).intValue(); // if (mSign == "-") // mAmount = mAmount * -1; // } // // public String toString() { // return "MoneyAmount24 " + mAmount; // } // // } // Path: code/android/RejsekortReader/src/info/rejsekort/reader/rkf/blocks/TCPUDynamicv6Block.java import info.rejsekort.reader.rkf.datatypes.DataType; import info.rejsekort.reader.rkf.datatypes.RKFInteger; import info.rejsekort.reader.rkf.datatypes.ByteString; import info.rejsekort.reader.rkf.datatypes.MoneyAmount24; package info.rejsekort.reader.rkf.blocks; public class TCPUDynamicv6Block extends InterpretedBlock { public RKFInteger mPurseTransactionNumber; public MoneyAmount24 mValue; public ByteString mXXX; public TCPUDynamicv6Block(byte[] bits) { super("TCPUDynamicv6", bits); mPurseTransactionNumber = new RKFInteger(16, true); mValue = new MoneyAmount24(24, true); mXXX = new ByteString(216, true);
mFields = new DataType[] {
shyampurk/bluemix-todo-app
Android-Client/app/src/main/java/adapters/TaskListAdapter.java
// Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // } // // Path: Android-Client/src/main/java/modals/TaskSummaryTemplate.java // public class TaskSummaryTemplate { // // private String DISPLAY_NAME=""; // private String TASK_STATUS=""; // private String TASK_DESCRIPTION=""; // private String NO_OF_COMMENTS=""; // private String TASK_CREATION_DATE=""; // private String TASK_NAME=""; // private String TASK_ID=""; // private String LAST_UPDATED=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getTASK_STATUS() { // return TASK_STATUS; // } // // public void setTASK_STATUS(String TASK_STATUS) { // this.TASK_STATUS = TASK_STATUS; // } // // public String getTASK_DESCRIPTION() { // return TASK_DESCRIPTION; // } // // public void setTASK_DESCRIPTION(String TASK_DESCRIPTION) { // this.TASK_DESCRIPTION = TASK_DESCRIPTION; // } // // public String getNO_OF_COMMENTS() { // return NO_OF_COMMENTS; // } // // public void setNO_OF_COMMENTS(String NO_OF_COMMENTS) { // this.NO_OF_COMMENTS = NO_OF_COMMENTS; // } // // public String getTASK_CREATION_DATE() { // return TASK_CREATION_DATE; // } // // public void setTASK_CREATION_DATE(String TASK_CREATION_DATE) { // this.TASK_CREATION_DATE = TASK_CREATION_DATE; // } // // public String getTASK_NAME() { // return TASK_NAME; // } // // public void setTASK_NAME(String TASK_NAME) { // this.TASK_NAME = TASK_NAME; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // // public String getLAST_UPDATED() { // return LAST_UPDATED; // } // // public void setLAST_UPDATED(String LAST_UPDATED) { // this.LAST_UPDATED = LAST_UPDATED; // } // }
import android.content.Context; import android.graphics.Color; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; import modals.TaskListing; import modals.TaskSummaryTemplate; import vitymobi.com.todobluemix.R;
package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskListAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
// Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // } // // Path: Android-Client/src/main/java/modals/TaskSummaryTemplate.java // public class TaskSummaryTemplate { // // private String DISPLAY_NAME=""; // private String TASK_STATUS=""; // private String TASK_DESCRIPTION=""; // private String NO_OF_COMMENTS=""; // private String TASK_CREATION_DATE=""; // private String TASK_NAME=""; // private String TASK_ID=""; // private String LAST_UPDATED=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getTASK_STATUS() { // return TASK_STATUS; // } // // public void setTASK_STATUS(String TASK_STATUS) { // this.TASK_STATUS = TASK_STATUS; // } // // public String getTASK_DESCRIPTION() { // return TASK_DESCRIPTION; // } // // public void setTASK_DESCRIPTION(String TASK_DESCRIPTION) { // this.TASK_DESCRIPTION = TASK_DESCRIPTION; // } // // public String getNO_OF_COMMENTS() { // return NO_OF_COMMENTS; // } // // public void setNO_OF_COMMENTS(String NO_OF_COMMENTS) { // this.NO_OF_COMMENTS = NO_OF_COMMENTS; // } // // public String getTASK_CREATION_DATE() { // return TASK_CREATION_DATE; // } // // public void setTASK_CREATION_DATE(String TASK_CREATION_DATE) { // this.TASK_CREATION_DATE = TASK_CREATION_DATE; // } // // public String getTASK_NAME() { // return TASK_NAME; // } // // public void setTASK_NAME(String TASK_NAME) { // this.TASK_NAME = TASK_NAME; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // // public String getLAST_UPDATED() { // return LAST_UPDATED; // } // // public void setLAST_UPDATED(String LAST_UPDATED) { // this.LAST_UPDATED = LAST_UPDATED; // } // } // Path: Android-Client/app/src/main/java/adapters/TaskListAdapter.java import android.content.Context; import android.graphics.Color; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; import modals.TaskListing; import modals.TaskSummaryTemplate; import vitymobi.com.todobluemix.R; package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskListAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
private TaskSummaryTemplate[] tasksData;
shyampurk/bluemix-todo-app
Android-Client/app/src/main/java/adapters/AddressBookAdapter.java
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/ContactTemplate.java // public class ContactTemplate { // // // // // private String DISPLAY_NAME; // private String USER_STATE; // private String EMAIL=""; // private String LAST_ACTIVITY_TIME=""; // private String USER_ID=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getUSER_STATE() { // return USER_STATE; // } // // public void setUSER_STATE(String USER_STATE) { // this.USER_STATE = USER_STATE; // } // // public String getEMAIL() { // return EMAIL; // } // // public void setEMAIL(String EMAIL) { // this.EMAIL = EMAIL; // } // // public String getLAST_ACTIVITY() { // return LAST_ACTIVITY_TIME; // } // // public void setLAST_ACTIVITY(String LAST_ACTIVITY) { // this.LAST_ACTIVITY_TIME = LAST_ACTIVITY; // } // // public String getUSER_ID() { // return USER_ID; // } // // public void setUSER_ID(String USER_ID) { // this.USER_ID = USER_ID; // } // }
import android.content.Context; import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import java.util.Arrays; import modals.CommentTemplate; import modals.ContactTemplate; import vitymobi.com.todobluemix.R;
package adapters; /** * Created by manishautomatic on 28/03/16. */ public class AddressBookAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/ContactTemplate.java // public class ContactTemplate { // // // // // private String DISPLAY_NAME; // private String USER_STATE; // private String EMAIL=""; // private String LAST_ACTIVITY_TIME=""; // private String USER_ID=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getUSER_STATE() { // return USER_STATE; // } // // public void setUSER_STATE(String USER_STATE) { // this.USER_STATE = USER_STATE; // } // // public String getEMAIL() { // return EMAIL; // } // // public void setEMAIL(String EMAIL) { // this.EMAIL = EMAIL; // } // // public String getLAST_ACTIVITY() { // return LAST_ACTIVITY_TIME; // } // // public void setLAST_ACTIVITY(String LAST_ACTIVITY) { // this.LAST_ACTIVITY_TIME = LAST_ACTIVITY; // } // // public String getUSER_ID() { // return USER_ID; // } // // public void setUSER_ID(String USER_ID) { // this.USER_ID = USER_ID; // } // } // Path: Android-Client/app/src/main/java/adapters/AddressBookAdapter.java import android.content.Context; import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import java.util.Arrays; import modals.CommentTemplate; import modals.ContactTemplate; import vitymobi.com.todobluemix.R; package adapters; /** * Created by manishautomatic on 28/03/16. */ public class AddressBookAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
private ArrayList<ContactTemplate> contactsList= new ArrayList<>();
shyampurk/bluemix-todo-app
Android-Client/src/main/java/adapters/TaskListAdapter.java
// Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // } // // Path: Android-Client/src/main/java/modals/TaskSummaryTemplate.java // public class TaskSummaryTemplate { // // private String DISPLAY_NAME=""; // private String TASK_STATUS=""; // private String TASK_DESCRIPTION=""; // private String NO_OF_COMMENTS=""; // private String TASK_CREATION_DATE=""; // private String TASK_NAME=""; // private String TASK_ID=""; // private String LAST_UPDATED=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getTASK_STATUS() { // return TASK_STATUS; // } // // public void setTASK_STATUS(String TASK_STATUS) { // this.TASK_STATUS = TASK_STATUS; // } // // public String getTASK_DESCRIPTION() { // return TASK_DESCRIPTION; // } // // public void setTASK_DESCRIPTION(String TASK_DESCRIPTION) { // this.TASK_DESCRIPTION = TASK_DESCRIPTION; // } // // public String getNO_OF_COMMENTS() { // return NO_OF_COMMENTS; // } // // public void setNO_OF_COMMENTS(String NO_OF_COMMENTS) { // this.NO_OF_COMMENTS = NO_OF_COMMENTS; // } // // public String getTASK_CREATION_DATE() { // return TASK_CREATION_DATE; // } // // public void setTASK_CREATION_DATE(String TASK_CREATION_DATE) { // this.TASK_CREATION_DATE = TASK_CREATION_DATE; // } // // public String getTASK_NAME() { // return TASK_NAME; // } // // public void setTASK_NAME(String TASK_NAME) { // this.TASK_NAME = TASK_NAME; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // // public String getLAST_UPDATED() { // return LAST_UPDATED; // } // // public void setLAST_UPDATED(String LAST_UPDATED) { // this.LAST_UPDATED = LAST_UPDATED; // } // }
import android.content.Context; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; import modals.TaskListing; import modals.TaskSummaryTemplate; import vitymobi.com.todobluemix.R;
package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskListAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
// Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // } // // Path: Android-Client/src/main/java/modals/TaskSummaryTemplate.java // public class TaskSummaryTemplate { // // private String DISPLAY_NAME=""; // private String TASK_STATUS=""; // private String TASK_DESCRIPTION=""; // private String NO_OF_COMMENTS=""; // private String TASK_CREATION_DATE=""; // private String TASK_NAME=""; // private String TASK_ID=""; // private String LAST_UPDATED=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getTASK_STATUS() { // return TASK_STATUS; // } // // public void setTASK_STATUS(String TASK_STATUS) { // this.TASK_STATUS = TASK_STATUS; // } // // public String getTASK_DESCRIPTION() { // return TASK_DESCRIPTION; // } // // public void setTASK_DESCRIPTION(String TASK_DESCRIPTION) { // this.TASK_DESCRIPTION = TASK_DESCRIPTION; // } // // public String getNO_OF_COMMENTS() { // return NO_OF_COMMENTS; // } // // public void setNO_OF_COMMENTS(String NO_OF_COMMENTS) { // this.NO_OF_COMMENTS = NO_OF_COMMENTS; // } // // public String getTASK_CREATION_DATE() { // return TASK_CREATION_DATE; // } // // public void setTASK_CREATION_DATE(String TASK_CREATION_DATE) { // this.TASK_CREATION_DATE = TASK_CREATION_DATE; // } // // public String getTASK_NAME() { // return TASK_NAME; // } // // public void setTASK_NAME(String TASK_NAME) { // this.TASK_NAME = TASK_NAME; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // // public String getLAST_UPDATED() { // return LAST_UPDATED; // } // // public void setLAST_UPDATED(String LAST_UPDATED) { // this.LAST_UPDATED = LAST_UPDATED; // } // } // Path: Android-Client/src/main/java/adapters/TaskListAdapter.java import android.content.Context; import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; import modals.TaskListing; import modals.TaskSummaryTemplate; import vitymobi.com.todobluemix.R; package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskListAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
private TaskSummaryTemplate[] tasksData;
shyampurk/bluemix-todo-app
Android-Client/src/main/java/adapters/AddressBookAdapter.java
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/ContactTemplate.java // public class ContactTemplate { // // // // // private String DISPLAY_NAME; // private String USER_STATE; // private String EMAIL=""; // private String LAST_ACTIVITY_TIME=""; // private String USER_ID=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getUSER_STATE() { // return USER_STATE; // } // // public void setUSER_STATE(String USER_STATE) { // this.USER_STATE = USER_STATE; // } // // public String getEMAIL() { // return EMAIL; // } // // public void setEMAIL(String EMAIL) { // this.EMAIL = EMAIL; // } // // public String getLAST_ACTIVITY() { // return LAST_ACTIVITY_TIME; // } // // public void setLAST_ACTIVITY(String LAST_ACTIVITY) { // this.LAST_ACTIVITY_TIME = LAST_ACTIVITY; // } // // public String getUSER_ID() { // return USER_ID; // } // // public void setUSER_ID(String USER_ID) { // this.USER_ID = USER_ID; // } // }
import android.content.Context; import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import modals.CommentTemplate; import modals.ContactTemplate; import vitymobi.com.todobluemix.R;
package adapters; /** * Created by manishautomatic on 28/03/16. */ public class AddressBookAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/ContactTemplate.java // public class ContactTemplate { // // // // // private String DISPLAY_NAME; // private String USER_STATE; // private String EMAIL=""; // private String LAST_ACTIVITY_TIME=""; // private String USER_ID=""; // // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getUSER_STATE() { // return USER_STATE; // } // // public void setUSER_STATE(String USER_STATE) { // this.USER_STATE = USER_STATE; // } // // public String getEMAIL() { // return EMAIL; // } // // public void setEMAIL(String EMAIL) { // this.EMAIL = EMAIL; // } // // public String getLAST_ACTIVITY() { // return LAST_ACTIVITY_TIME; // } // // public void setLAST_ACTIVITY(String LAST_ACTIVITY) { // this.LAST_ACTIVITY_TIME = LAST_ACTIVITY; // } // // public String getUSER_ID() { // return USER_ID; // } // // public void setUSER_ID(String USER_ID) { // this.USER_ID = USER_ID; // } // } // Path: Android-Client/src/main/java/adapters/AddressBookAdapter.java import android.content.Context; import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import modals.CommentTemplate; import modals.ContactTemplate; import vitymobi.com.todobluemix.R; package adapters; /** * Created by manishautomatic on 28/03/16. */ public class AddressBookAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
private ContactTemplate[] contactsList;
shyampurk/bluemix-todo-app
Android-Client/src/main/java/adapters/TaskCommentsAdapter.java
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // }
import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import java.lang.reflect.Array; import java.util.ArrayList; import modals.CommentTemplate; import modals.TaskListing; import vitymobi.com.todobluemix.R;
package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskCommentsAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
// Path: Android-Client/src/main/java/modals/CommentTemplate.java // public class CommentTemplate { // // private String DISPLAY_NAME=""; // private String COMMENT_CREATION_DATE=""; // private String COMMENT_DESCRIPTION=""; // private String ORDER=""; // private String TASK_ID=""; // // public String getDISPLAY_NAME() { // return DISPLAY_NAME; // } // // public void setDISPLAY_NAME(String DISPLAY_NAME) { // this.DISPLAY_NAME = DISPLAY_NAME; // } // // public String getCOMMENT_CREATION_DATE() { // return COMMENT_CREATION_DATE; // } // // public void setCOMMENT_CREATION_DATE(String COMMENT_CREATION_DATE) { // this.COMMENT_CREATION_DATE = COMMENT_CREATION_DATE; // } // // public String getCOMMENT_DESCRIPTION() { // return COMMENT_DESCRIPTION; // } // // public void setCOMMENT_DESCRIPTION(String COMMENT_DESCRIPTION) { // this.COMMENT_DESCRIPTION = COMMENT_DESCRIPTION; // } // // public String getORDER() { // return ORDER; // } // // public void setORDER(String ORDER) { // this.ORDER = ORDER; // } // // public String getTASK_ID() { // return TASK_ID; // } // // public void setTASK_ID(String TASK_ID) { // this.TASK_ID = TASK_ID; // } // } // // Path: Android-Client/src/main/java/modals/TaskListing.java // public class TaskListing { // // // private ArrayList<TaskTemplate> mTasks = new ArrayList<>(); // // // public ArrayList<TaskTemplate> getmTasks() { // return mTasks; // } // // public void setmTasks(ArrayList<TaskTemplate> mTasks) { // this.mTasks = mTasks; // } // } // Path: Android-Client/src/main/java/adapters/TaskCommentsAdapter.java import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import java.lang.reflect.Array; import java.util.ArrayList; import modals.CommentTemplate; import modals.TaskListing; import vitymobi.com.todobluemix.R; package adapters; /** * Created by manishautomatic on 28/03/16. */ public class TaskCommentsAdapter extends BaseAdapter { private Context parentContext; private LayoutInflater mInflater;
private ArrayList<CommentTemplate> taskComments;
restsql/restsql
src/org/restsql/service/LogResource.java
// Path: src/org/restsql/service/monitoring/MonitoringFactory.java // public class MonitoringFactory extends AbstractFactory { // // /** Returns MonitoringManager singleton. */ // public static MonitoringManager getMonitoringManager() { // return (MonitoringManager) getInstance(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // /** Returns configured MonitoringManager class name. */ // public static String getMonitoringManagerClass() { // return Config.properties.getProperty(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.restsql.core.Config; import org.restsql.service.monitoring.MonitoringFactory; import com.codahale.metrics.Counter;
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.service; /** * Provides access to logs. * * @author Mark Sawers */ @Path("log") public class LogResource { private static final String LOG_NAME_ACCESS = "access.log"; private static final String LOG_NAME_ERROR = "error.log"; private static final String LOG_NAME_INTERNAL = "internal.log"; private static final String LOG_NAME_TRACE = "trace.log";
// Path: src/org/restsql/service/monitoring/MonitoringFactory.java // public class MonitoringFactory extends AbstractFactory { // // /** Returns MonitoringManager singleton. */ // public static MonitoringManager getMonitoringManager() { // return (MonitoringManager) getInstance(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // /** Returns configured MonitoringManager class name. */ // public static String getMonitoringManagerClass() { // return Config.properties.getProperty(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // } // Path: src/org/restsql/service/LogResource.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.restsql.core.Config; import org.restsql.service.monitoring.MonitoringFactory; import com.codahale.metrics.Counter; /* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.service; /** * Provides access to logs. * * @author Mark Sawers */ @Path("log") public class LogResource { private static final String LOG_NAME_ACCESS = "access.log"; private static final String LOG_NAME_ERROR = "error.log"; private static final String LOG_NAME_INTERNAL = "internal.log"; private static final String LOG_NAME_TRACE = "trace.log";
private final Counter logAccessCounter = MonitoringFactory.getMonitoringManager().newCounter(LogResource.class, "logAccess");
restsql/restsql
src/org/restsql/service/ToolsResource.java
// Path: src/org/restsql/service/monitoring/MonitoringFactory.java // public class MonitoringFactory extends AbstractFactory { // // /** Returns MonitoringManager singleton. */ // public static MonitoringManager getMonitoringManager() { // return (MonitoringManager) getInstance(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // /** Returns configured MonitoringManager class name. */ // public static String getMonitoringManagerClass() { // return Config.properties.getProperty(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // }
import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.restsql.service.monitoring.MonitoringFactory; import org.restsql.tools.ResourceDefinitionGenerator; import org.restsql.tools.ToolsFactory; import com.codahale.metrics.Counter;
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.service; /** * Provides utilities to users. * * @author Mark Sawers */ @Path("tools") public class ToolsResource { private final static String BASE_HTML = "<!DOCTYPE html>\n<html><head><link rel=\"icon\" type=\"image/png\" href=\"../assets/favicon.ico\"/></head><body style=\"font-family:sans-serif\">" + "<span style=\"font-weight:bold\"><a href=\"../..\">restSQL</a> Tools: Generate Resource Definitions</span><hr/>";
// Path: src/org/restsql/service/monitoring/MonitoringFactory.java // public class MonitoringFactory extends AbstractFactory { // // /** Returns MonitoringManager singleton. */ // public static MonitoringManager getMonitoringManager() { // return (MonitoringManager) getInstance(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // /** Returns configured MonitoringManager class name. */ // public static String getMonitoringManagerClass() { // return Config.properties.getProperty(Config.KEY_MONITORING_MANAGER, Config.DEFAULT_MONITORING_MANAGER); // } // // } // Path: src/org/restsql/service/ToolsResource.java import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.restsql.service.monitoring.MonitoringFactory; import org.restsql.tools.ResourceDefinitionGenerator; import org.restsql.tools.ToolsFactory; import com.codahale.metrics.Counter; /* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.service; /** * Provides utilities to users. * * @author Mark Sawers */ @Path("tools") public class ToolsResource { private final static String BASE_HTML = "<!DOCTYPE html>\n<html><head><link rel=\"icon\" type=\"image/png\" href=\"../assets/favicon.ico\"/></head><body style=\"font-family:sans-serif\">" + "<span style=\"font-weight:bold\"><a href=\"../..\">restSQL</a> Tools: Generate Resource Definitions</span><hr/>";
private final Counter requestCounter = MonitoringFactory.getMonitoringManager().newCounter(ToolsResource.class, "tools");
restsql/restsql
src/org/restsql/core/impl/serial/JsonResponseSerializer.java
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // }
import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.restsql.core.ColumnMetaData; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse;
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.core.impl.serial; /** * Converts read/write results to a JSON string. * * @author Mark Sawers */ public class JsonResponseSerializer implements ResponseSerializer { @Override public String getSupportedMediaType() { return "application/json"; } /** * Converts flat select results to a JSON array. * * @param sqlResource SQL resource * @param resultSet results * @return JSON string */ // TODO: move column get from metadata outside of result set while loop!!! @Override
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // } // Path: src/org/restsql/core/impl/serial/JsonResponseSerializer.java import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.restsql.core.ColumnMetaData; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse; /* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.core.impl.serial; /** * Converts read/write results to a JSON string. * * @author Mark Sawers */ public class JsonResponseSerializer implements ResponseSerializer { @Override public String getSupportedMediaType() { return "application/json"; } /** * Converts flat select results to a JSON array. * * @param sqlResource SQL resource * @param resultSet results * @return JSON string */ // TODO: move column get from metadata outside of result set while loop!!! @Override
public String serializeReadFlat(final SqlResource sqlResource, final ResultSet resultSet)
restsql/restsql
src/org/restsql/core/impl/serial/JsonResponseSerializer.java
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // }
import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.restsql.core.ColumnMetaData; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse;
} else { childRows = (List<Map<String, Object>>) value; } } // Do embedded child object columns if (level == 1 && childRows.size() > 0) { body.append(",\n\t\t\t\""); body.append(sqlResource.getMetaData().getChild().getRowSetAlias()); body.append("\": ["); serializeReadRowsHierarchical(sqlResource, childRows, body, 2); body.append("\n\t\t\t]"); } // Add line ending if (level == 1 && childRows.size() > 0) { body.append("\n\t\t}"); } else { body.append(" }"); } if (!lastRow) { body.append(","); } } } /** One-level recursive method to serialize hierarchical results. */ @SuppressWarnings("unchecked") private void serializeWriteRowsHierarchical(final SqlResource sqlResource,
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // } // Path: src/org/restsql/core/impl/serial/JsonResponseSerializer.java import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.restsql.core.ColumnMetaData; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse; } else { childRows = (List<Map<String, Object>>) value; } } // Do embedded child object columns if (level == 1 && childRows.size() > 0) { body.append(",\n\t\t\t\""); body.append(sqlResource.getMetaData().getChild().getRowSetAlias()); body.append("\": ["); serializeReadRowsHierarchical(sqlResource, childRows, body, 2); body.append("\n\t\t\t]"); } // Add line ending if (level == 1 && childRows.size() > 0) { body.append("\n\t\t}"); } else { body.append(" }"); } if (!lastRow) { body.append(","); } } } /** One-level recursive method to serialize hierarchical results. */ @SuppressWarnings("unchecked") private void serializeWriteRowsHierarchical(final SqlResource sqlResource,
final List<Set<ResponseValue>> rows, final StringBuilder body, final int level) {
restsql/restsql
src/org/restsql/core/Factory.java
// Path: src/org/restsql/core/Request.java // public enum Type { // DELETE, INSERT, SELECT, UPDATE; // // public static Type fromHttpMethod(final String method) { // Type type; // if (method.equals("DELETE")) { // type = Type.DELETE; // } else if (method.equals("GET")) { // type = Type.SELECT; // } else if (method.equals("POST")) { // type = Type.INSERT; // } else { // method.equals("PUT") // type = Type.UPDATE; // } // return type; // } // } // // Path: src/org/restsql/core/sqlresource/SqlResourceDefinition.java // @XmlRootElement(name = "sqlResource", namespace = "http://restsql.org/schema") // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "SqlResource", propOrder = { // "query", // "metadata", // "validatedAttribute", // "http", // "documentation" // }) // public class SqlResourceDefinition { // // @XmlElement(required = true) // protected Query query; // @XmlElement(required = true) // protected MetaData metadata; // protected List<ValidatedAttribute> validatedAttribute; // protected HttpConfig http; // protected Documentation documentation; // // /** // * Gets the value of the query property. // * // * @return // * possible object is // * {@link Query } // * // */ // public Query getQuery() { // return query; // } // // /** // * Sets the value of the query property. // * // * @param value // * allowed object is // * {@link Query } // * // */ // public void setQuery(Query value) { // this.query = value; // } // // /** // * Gets the value of the metadata property. // * // * @return // * possible object is // * {@link MetaData } // * // */ // public MetaData getMetadata() { // return metadata; // } // // /** // * Sets the value of the metadata property. // * // * @param value // * allowed object is // * {@link MetaData } // * // */ // public void setMetadata(MetaData value) { // this.metadata = value; // } // // /** // * Gets the value of the validatedAttribute property. // * // * <p> // * This accessor method returns a reference to the live list, // * not a snapshot. Therefore any modification you make to the // * returned list will be present inside the JAXB object. // * This is why there is not a <CODE>set</CODE> method for the validatedAttribute property. // * // * <p> // * For example, to add a new item, do as follows: // * <pre> // * getValidatedAttribute().add(newItem); // * </pre> // * // * // * <p> // * Objects of the following type(s) are allowed in the list // * {@link ValidatedAttribute } // * // * // */ // public List<ValidatedAttribute> getValidatedAttribute() { // if (validatedAttribute == null) { // validatedAttribute = new ArrayList<ValidatedAttribute>(); // } // return this.validatedAttribute; // } // // /** // * Gets the value of the http property. // * // * @return // * possible object is // * {@link HttpConfig } // * // */ // public HttpConfig getHttp() { // return http; // } // // /** // * Sets the value of the http property. // * // * @param value // * allowed object is // * {@link HttpConfig } // * // */ // public void setHttp(HttpConfig value) { // this.http = value; // } // // /** // * Gets the value of the documentation property. // * // * @return // * possible object is // * {@link Documentation } // * // */ // public Documentation getDocumentation() { // return documentation; // } // // /** // * Sets the value of the documentation property. // * // * @param value // * allowed object is // * {@link Documentation } // * // */ // public void setDocumentation(Documentation value) { // this.documentation = value; // } // // }
import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.restsql.core.Request.Type; import org.restsql.core.sqlresource.SqlResourceDefinition;
* * @param resName resource name * @return SQLResource object * @throws SqlResourceFactoryException if the definition could not be marshalled * @throws SqlResourceException if a database error occurs while collecting metadata */ public static SqlResource getSqlResource(final String resName) throws SqlResourceFactoryException, SqlResourceException { final SqlResourceFactory sqlResourceFactory = (SqlResourceFactory) getInstance( Config.KEY_SQL_RESOURCE_FACTORY, Config.DEFAULT_SQL_RESOURCE_FACTORY); return sqlResourceFactory.getSqlResource(resName); } /** * Returns definition content as input stream. Configurable implementation class. */ public static InputStream getSqlResourceDefinition(final String resName) throws SqlResourceFactoryException { final SqlResourceFactory sqlResourceFactory = (SqlResourceFactory) getInstance( Config.KEY_SQL_RESOURCE_FACTORY, Config.DEFAULT_SQL_RESOURCE_FACTORY); return sqlResourceFactory.getSqlResourceDefinition(resName); } /** * Returns meta data object for definition. Configurable implementation class. * @param sqlBuilder db-specific SQL builder * * @throws SqlResourceException if a database access error occurs */ public static SqlResourceMetaData getSqlResourceMetaData(final String resName,
// Path: src/org/restsql/core/Request.java // public enum Type { // DELETE, INSERT, SELECT, UPDATE; // // public static Type fromHttpMethod(final String method) { // Type type; // if (method.equals("DELETE")) { // type = Type.DELETE; // } else if (method.equals("GET")) { // type = Type.SELECT; // } else if (method.equals("POST")) { // type = Type.INSERT; // } else { // method.equals("PUT") // type = Type.UPDATE; // } // return type; // } // } // // Path: src/org/restsql/core/sqlresource/SqlResourceDefinition.java // @XmlRootElement(name = "sqlResource", namespace = "http://restsql.org/schema") // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "SqlResource", propOrder = { // "query", // "metadata", // "validatedAttribute", // "http", // "documentation" // }) // public class SqlResourceDefinition { // // @XmlElement(required = true) // protected Query query; // @XmlElement(required = true) // protected MetaData metadata; // protected List<ValidatedAttribute> validatedAttribute; // protected HttpConfig http; // protected Documentation documentation; // // /** // * Gets the value of the query property. // * // * @return // * possible object is // * {@link Query } // * // */ // public Query getQuery() { // return query; // } // // /** // * Sets the value of the query property. // * // * @param value // * allowed object is // * {@link Query } // * // */ // public void setQuery(Query value) { // this.query = value; // } // // /** // * Gets the value of the metadata property. // * // * @return // * possible object is // * {@link MetaData } // * // */ // public MetaData getMetadata() { // return metadata; // } // // /** // * Sets the value of the metadata property. // * // * @param value // * allowed object is // * {@link MetaData } // * // */ // public void setMetadata(MetaData value) { // this.metadata = value; // } // // /** // * Gets the value of the validatedAttribute property. // * // * <p> // * This accessor method returns a reference to the live list, // * not a snapshot. Therefore any modification you make to the // * returned list will be present inside the JAXB object. // * This is why there is not a <CODE>set</CODE> method for the validatedAttribute property. // * // * <p> // * For example, to add a new item, do as follows: // * <pre> // * getValidatedAttribute().add(newItem); // * </pre> // * // * // * <p> // * Objects of the following type(s) are allowed in the list // * {@link ValidatedAttribute } // * // * // */ // public List<ValidatedAttribute> getValidatedAttribute() { // if (validatedAttribute == null) { // validatedAttribute = new ArrayList<ValidatedAttribute>(); // } // return this.validatedAttribute; // } // // /** // * Gets the value of the http property. // * // * @return // * possible object is // * {@link HttpConfig } // * // */ // public HttpConfig getHttp() { // return http; // } // // /** // * Sets the value of the http property. // * // * @param value // * allowed object is // * {@link HttpConfig } // * // */ // public void setHttp(HttpConfig value) { // this.http = value; // } // // /** // * Gets the value of the documentation property. // * // * @return // * possible object is // * {@link Documentation } // * // */ // public Documentation getDocumentation() { // return documentation; // } // // /** // * Sets the value of the documentation property. // * // * @param value // * allowed object is // * {@link Documentation } // * // */ // public void setDocumentation(Documentation value) { // this.documentation = value; // } // // } // Path: src/org/restsql/core/Factory.java import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import org.restsql.core.Request.Type; import org.restsql.core.sqlresource.SqlResourceDefinition; * * @param resName resource name * @return SQLResource object * @throws SqlResourceFactoryException if the definition could not be marshalled * @throws SqlResourceException if a database error occurs while collecting metadata */ public static SqlResource getSqlResource(final String resName) throws SqlResourceFactoryException, SqlResourceException { final SqlResourceFactory sqlResourceFactory = (SqlResourceFactory) getInstance( Config.KEY_SQL_RESOURCE_FACTORY, Config.DEFAULT_SQL_RESOURCE_FACTORY); return sqlResourceFactory.getSqlResource(resName); } /** * Returns definition content as input stream. Configurable implementation class. */ public static InputStream getSqlResourceDefinition(final String resName) throws SqlResourceFactoryException { final SqlResourceFactory sqlResourceFactory = (SqlResourceFactory) getInstance( Config.KEY_SQL_RESOURCE_FACTORY, Config.DEFAULT_SQL_RESOURCE_FACTORY); return sqlResourceFactory.getSqlResourceDefinition(resName); } /** * Returns meta data object for definition. Configurable implementation class. * @param sqlBuilder db-specific SQL builder * * @throws SqlResourceException if a database access error occurs */ public static SqlResourceMetaData getSqlResourceMetaData(final String resName,
final SqlResourceDefinition definition, SqlBuilder sqlBuilder) throws SqlResourceException {
restsql/restsql
src/org/restsql/core/impl/serial/XmlResponseSerializer.java
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // }
import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.restsql.core.ColumnMetaData; import org.restsql.core.Config; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse;
/* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.core.impl.serial; /** * Converts read/write results to an XML document. * * @author Mark Sawers */ public class XmlResponseSerializer implements ResponseSerializer { private static boolean useXmlDirective = Boolean.valueOf(Config.properties.getProperty( Config.KEY_RESPONSE_USE_XML_DIRECTIVE, Config.DEFAULT_RESPONSE_USE_XML_DIRECTIVE)); private static boolean useXmlSchema = Boolean.valueOf(Config.properties.getProperty( Config.KEY_RESPONSE_USE_XML_SCHEMA, Config.DEFAULT_RESPONSE_USE_XML_SCHEMA)); /** Overrides configuration. For test use only. */ public static void setUseXmlDirective(final boolean use) { useXmlDirective = use; } /** Overrides configuration. For test use only. */ public static void setUseXmlSchema(final boolean use) { useXmlSchema = use; } @Override public String getSupportedMediaType() { return "application/xml"; } /** * Converts flat select results to an XML document. * * @param sqlResource SQL resource * @param resultSet results * @return XML doc */ @Override
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // } // Path: src/org/restsql/core/impl/serial/XmlResponseSerializer.java import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.restsql.core.ColumnMetaData; import org.restsql.core.Config; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse; /* Copyright (c) restSQL Project Contributors. Licensed under MIT. */ package org.restsql.core.impl.serial; /** * Converts read/write results to an XML document. * * @author Mark Sawers */ public class XmlResponseSerializer implements ResponseSerializer { private static boolean useXmlDirective = Boolean.valueOf(Config.properties.getProperty( Config.KEY_RESPONSE_USE_XML_DIRECTIVE, Config.DEFAULT_RESPONSE_USE_XML_DIRECTIVE)); private static boolean useXmlSchema = Boolean.valueOf(Config.properties.getProperty( Config.KEY_RESPONSE_USE_XML_SCHEMA, Config.DEFAULT_RESPONSE_USE_XML_SCHEMA)); /** Overrides configuration. For test use only. */ public static void setUseXmlDirective(final boolean use) { useXmlDirective = use; } /** Overrides configuration. For test use only. */ public static void setUseXmlSchema(final boolean use) { useXmlSchema = use; } @Override public String getSupportedMediaType() { return "application/xml"; } /** * Converts flat select results to an XML document. * * @param sqlResource SQL resource * @param resultSet results * @return XML doc */ @Override
public String serializeReadFlat(final SqlResource sqlResource, final ResultSet resultSet)
restsql/restsql
src/org/restsql/core/impl/serial/XmlResponseSerializer.java
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // }
import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.restsql.core.ColumnMetaData; import org.restsql.core.Config; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse;
for (final String columnLabel : row.keySet()) { final Object value = row.get(columnLabel); if (value instanceof List<?> && ((List<?>) value).size() > 0) { hasChildren = true; body.append(">"); @SuppressWarnings("unchecked") final List<Map<String, Object>> childRows = (List<Map<String, Object>>) value; serializeReadRowsHierarchical(sqlResource, childRows, body, 2); } } // Close element if (level == 1) { if (hasChildren) { // Enclose the children with the parent end element body.append("\n\t</"); body.append(tableAlias); body.append(">"); } else { // Close the parent body.append(" />"); } } else { // level == 2 // Close the child body.append(" />"); } } } /** One-level recursive method to serialize hierarchical results. */
// Path: src/org/restsql/core/ResponseValue.java // public class ResponseValue implements Comparable<ResponseValue> { // private final String name; // private final Object value; // private final int columnNumber; // // public ResponseValue(final String name, final Object value, final int columnNumber) { // this.name = name; // this.value = value; // this.columnNumber = columnNumber; // } // // @Override // public int compareTo(ResponseValue value) { // if (columnNumber < value.getColumnNumber()) { // return -1; // } else if (columnNumber > value.getColumnNumber()) { // return 1; // } else { // return 0; // } // } // // /** Returns true if the names, values and column numbers are equal. */ // @Override // public boolean equals(Object o) { // return ((ResponseValue) o).getName().equals(name) && ((ResponseValue) o).getValue().equals(value) // && ((ResponseValue) o).getColumnNumber() == columnNumber; // } // // /** Returns column number in the select clause in the SQL Resource definition query. */ // public int getColumnNumber() { // return columnNumber; // } // // /** Returns name. */ // public String getName() { // return name; // } // // /** Returns value. */ // public Object getValue() { // return value; // } // // @Override // public int hashCode() { // return name.hashCode() + value.hashCode(); // } // // /** Returns string representation in the form <code>name: value</code>. */ // @Override // public String toString() { // return name + ": " + value; // } // } // // Path: src/org/restsql/core/SqlResource.java // public interface SqlResource { // /** // * Returns SQL resource information defined by the user, including query, validated attributes and trigger. // * // * @return definition // */ // public SqlResourceDefinition getDefinition(); // // /** // * Returns SQL resource name. // * // * @return SQL resource name // */ // public String getName(); // // /** // * Returns meta data for SQL resource. // * // * @return SQL rsource meta data // */ // public SqlResourceMetaData getMetaData(); // // /** // * Returns triggers classes. // * // * @return list of trigger classes // */ // public List<Trigger> getTriggers(); // // /** // * Executes query returning results as an object collection. // * // * @param request Request object // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public List<Map<String, Object>> read(Request request) throws SqlResourceException; // // /** // * Executes query returning results as a string. // * // * @param request Request object // * @param mediaType response format, use internet media type e.g. application/xml // * @throws SqlResourceException if a database access error occurs // * @return list of rows, where each row is a map of name-value pairs // */ // public String read(final Request request, final String mediaType) throws SqlResourceException; // // /** // * Executes database write (insert, update or delete). // * // * @param request Request object // * @throws SqlResourceException if the request is invalid or a database access error or trigger exception occurs // * @return write response // */ // public WriteResponse write(final Request request) throws SqlResourceException; // } // Path: src/org/restsql/core/impl/serial/XmlResponseSerializer.java import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringEscapeUtils; import org.restsql.core.ColumnMetaData; import org.restsql.core.Config; import org.restsql.core.ResponseSerializer; import org.restsql.core.ResponseValue; import org.restsql.core.SqlResource; import org.restsql.core.WriteResponse; for (final String columnLabel : row.keySet()) { final Object value = row.get(columnLabel); if (value instanceof List<?> && ((List<?>) value).size() > 0) { hasChildren = true; body.append(">"); @SuppressWarnings("unchecked") final List<Map<String, Object>> childRows = (List<Map<String, Object>>) value; serializeReadRowsHierarchical(sqlResource, childRows, body, 2); } } // Close element if (level == 1) { if (hasChildren) { // Enclose the children with the parent end element body.append("\n\t</"); body.append(tableAlias); body.append(">"); } else { // Close the parent body.append(" />"); } } else { // level == 2 // Close the child body.append(" />"); } } } /** One-level recursive method to serialize hierarchical results. */
private void serializeWriteRows(final SqlResource sqlResource, final List<Set<ResponseValue>> rows,
Whiley/Jasm
src/main/java/jasm/lang/JvmTypes.java
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // }
import jasm.util.Pair; import java.util.*;
*/ public static JvmType.Reference substitute(JvmType.Reference type, Map<String,JvmType.Reference> binding) { if (type instanceof JvmType.Variable) { // Ok, we've reached a type variable, so we can now bind this with // what we already have. JvmType.Variable v = (JvmType.Variable) type; JvmType.Reference r = binding.get(v.variable()); if(r == null) { // if the variable is not part of the binding, then we simply do // not do anything with it. return v; } else { return r; } } else if(type instanceof JvmType.Wildcard) { JvmType.Wildcard wc = (JvmType.Wildcard) type; JvmType.Reference lb = wc.lowerBound(); JvmType.Reference ub = wc.upperBound(); if(lb != null) { lb = substitute(lb,binding); } if(ub != null) { ub = substitute(ub,binding); } return new JvmType.Wildcard(lb,ub); } else if(type instanceof JvmType.Array) { JvmType.Array at = (JvmType.Array) type; if(at.element() instanceof JvmType.Reference) { return new JvmType.Array(substitute((JvmType.Reference) at.element(),binding)); } else { return type; } } else if(type instanceof JvmType.Clazz) { JvmType.Clazz ct = (JvmType.Clazz) type;
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // } // Path: src/main/java/jasm/lang/JvmTypes.java import jasm.util.Pair; import java.util.*; */ public static JvmType.Reference substitute(JvmType.Reference type, Map<String,JvmType.Reference> binding) { if (type instanceof JvmType.Variable) { // Ok, we've reached a type variable, so we can now bind this with // what we already have. JvmType.Variable v = (JvmType.Variable) type; JvmType.Reference r = binding.get(v.variable()); if(r == null) { // if the variable is not part of the binding, then we simply do // not do anything with it. return v; } else { return r; } } else if(type instanceof JvmType.Wildcard) { JvmType.Wildcard wc = (JvmType.Wildcard) type; JvmType.Reference lb = wc.lowerBound(); JvmType.Reference ub = wc.upperBound(); if(lb != null) { lb = substitute(lb,binding); } if(ub != null) { ub = substitute(ub,binding); } return new JvmType.Wildcard(lb,ub); } else if(type instanceof JvmType.Array) { JvmType.Array at = (JvmType.Array) type; if(at.element() instanceof JvmType.Reference) { return new JvmType.Array(substitute((JvmType.Reference) at.element(),binding)); } else { return type; } } else if(type instanceof JvmType.Clazz) { JvmType.Clazz ct = (JvmType.Clazz) type;
ArrayList<Pair<String,List<JvmType.Reference>>> ncomponents = new ArrayList();
Whiley/Jasm
src/main/java/jasm/lang/ClassFile.java
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // }
import jasm.attributes.*; import jasm.util.Pair; import java.util.*;
* The type to generate the descriptor for * @param generic * True indicates generic information should be included. * @return */ public static String descriptor(JvmType t, boolean generic) { if(t instanceof JvmType.Bool) { return "Z"; } if(t instanceof JvmType.Byte) { return "B"; } else if(t instanceof JvmType.Char) { return "C"; } else if(t instanceof JvmType.Short) { return "S"; } else if(t instanceof JvmType.Int) { return "I"; } else if(t instanceof JvmType.Long) { return "J"; } else if(t instanceof JvmType.Float) { return "F"; } else if(t instanceof JvmType.Double) { return "D"; } else if(t instanceof JvmType.Void) { return "V"; } else if(t instanceof JvmType.Array) { JvmType.Array at = (JvmType.Array) t; return "[" + descriptor(at.element(),generic); } else if(t instanceof JvmType.Clazz) { JvmType.Clazz ref = (JvmType.Clazz) t; String r = "L" + ref.pkg().replace(".","/");
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // } // Path: src/main/java/jasm/lang/ClassFile.java import jasm.attributes.*; import jasm.util.Pair; import java.util.*; * The type to generate the descriptor for * @param generic * True indicates generic information should be included. * @return */ public static String descriptor(JvmType t, boolean generic) { if(t instanceof JvmType.Bool) { return "Z"; } if(t instanceof JvmType.Byte) { return "B"; } else if(t instanceof JvmType.Char) { return "C"; } else if(t instanceof JvmType.Short) { return "S"; } else if(t instanceof JvmType.Int) { return "I"; } else if(t instanceof JvmType.Long) { return "J"; } else if(t instanceof JvmType.Float) { return "F"; } else if(t instanceof JvmType.Double) { return "D"; } else if(t instanceof JvmType.Void) { return "V"; } else if(t instanceof JvmType.Array) { JvmType.Array at = (JvmType.Array) t; return "[" + descriptor(at.element(),generic); } else if(t instanceof JvmType.Clazz) { JvmType.Clazz ref = (JvmType.Clazz) t; String r = "L" + ref.pkg().replace(".","/");
List<Pair<String, List<JvmType.Reference>>> classes = ref.components();
Whiley/Jasm
src/main/java/jasm/lang/Bytecode.java
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // }
import jasm.util.Pair; import java.io.ByteArrayOutputStream; import java.util.*;
return out.toByteArray(); } public IfCmp fixLong() { return new IfCmp(cond,type,label,true); } public String toString() { if(type instanceof JvmType.Int) { return "if_icmp" + str[cond] + " " + label; } else { return "if_acmp" + str[cond] + " " + label; } } public boolean equals(Object o) { if (o instanceof IfCmp) { IfCmp b = (IfCmp) o; return cond == b.cond && type.equals(b.type) && label.equals(b.label) && islong == b.islong; } return false; } public int hashCode() { return label.hashCode() + type.hashCode(); } }
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // } // Path: src/main/java/jasm/lang/Bytecode.java import jasm.util.Pair; import java.io.ByteArrayOutputStream; import java.util.*; return out.toByteArray(); } public IfCmp fixLong() { return new IfCmp(cond,type,label,true); } public String toString() { if(type instanceof JvmType.Int) { return "if_icmp" + str[cond] + " " + label; } else { return "if_acmp" + str[cond] + " " + label; } } public boolean equals(Object o) { if (o instanceof IfCmp) { IfCmp b = (IfCmp) o; return cond == b.cond && type.equals(b.type) && label.equals(b.label) && islong == b.islong; } return false; } public int hashCode() { return label.hashCode() + type.hashCode(); } }
public static final Comparator<Pair<Integer, String>> switchcomp = new Comparator<Pair<Integer, String>>() {
Whiley/Jasm
src/main/java/jasm/io/ClassFileReader.java
// Path: src/main/java/jasm/io/BinaryInputStream.java // public class BinaryInputStream extends InputStream { // protected InputStream input; // protected int value; // protected int count; // // public BinaryInputStream(InputStream input) { // this.input = input; // } // // public int read() throws IOException { // if(count == 0) { // return input.read(); // } else { // return read_un(8); // } // } // // public int read(byte[] bytes) throws IOException { // for (int i = 0; i != bytes.length; ++i) { // bytes[i] = (byte) read(); // } // return bytes.length; // } // // public int read(byte[] bytes, int offset, int length) throws IOException { // for(;offset < length;++offset) { // bytes[offset] = (byte) read(); // } // return length; // } // // public int read_u8() throws IOException { // if(count == 0) { // return input.read() & 0xFF; // } else { // return read_un(8); // } // } // // public int read_u16() throws IOException { // return (read_u8() << 8) | read_u8(); // } // // public long read_u32() throws IOException { // // FIXME: this is most definitely broken // return (read_u8() << 24) | (read_u8() << 16) | (read_u8() << 8) // | read_u8(); // } // // public int read_un(int n) throws IOException { // int value = 0; // int mask = 1; // for(int i=0;i!=n;++i) { // if(read_bit()) { // value |= mask; // } // mask = mask << 1; // } // return value; // } // // public int read_uv() throws IOException { // int value = 0; // boolean flag = true; // int shift = 0; // while(flag) { // int w = read_un(4); // flag = (w&8) != 0; // value = ((w&7)<<shift) | value; // shift = shift + 3; // } // return value; // } // // public boolean read_bit() throws IOException { // if(count == 0) { // value = input.read(); // if(value < 0) { throw new EOFException(); } // count = 8; // } // boolean r = (value&1) != 0; // value = value >> 1; // count = count - 1; // return r; // } // // public void pad_u8() throws IOException { // count = 0; // easy!! // } // }
import java.io.*; import java.util.*; import jasm.attributes.*; import jasm.io.BinaryInputStream; import jasm.lang.*; import jasm.util.*;
int len = read_i4(index + 2); r.add(parseAttribute(index, enclosingMethod, enclosingClass)); index += len + 6; } return r; } protected BytecodeAttribute parseAttribute(int offset, ClassFile.Method enclosingMethod, ClassFile enclosingClass) { String name = getString(read_u2(offset)); if (name.equals("Code")) { return parseCode(offset, name, enclosingMethod); } else if (name.equals("Exceptions")) { return parseExceptions(offset, name); } else if (name.equals("InnerClasses")) { return parseInnerClasses(offset, name, enclosingClass.type()); } else if (name.equals("ConstantValue")) { return parseConstantValue(offset, name); } int len = read_i4(offset + 2) + 6; byte[] bs = new byte[len]; for (int i = 0; i != len; ++i) { bs[i] = bytes[offset + i]; } BytecodeAttribute.Reader reader = attributeReaders.get(name); if (reader != null) { try {
// Path: src/main/java/jasm/io/BinaryInputStream.java // public class BinaryInputStream extends InputStream { // protected InputStream input; // protected int value; // protected int count; // // public BinaryInputStream(InputStream input) { // this.input = input; // } // // public int read() throws IOException { // if(count == 0) { // return input.read(); // } else { // return read_un(8); // } // } // // public int read(byte[] bytes) throws IOException { // for (int i = 0; i != bytes.length; ++i) { // bytes[i] = (byte) read(); // } // return bytes.length; // } // // public int read(byte[] bytes, int offset, int length) throws IOException { // for(;offset < length;++offset) { // bytes[offset] = (byte) read(); // } // return length; // } // // public int read_u8() throws IOException { // if(count == 0) { // return input.read() & 0xFF; // } else { // return read_un(8); // } // } // // public int read_u16() throws IOException { // return (read_u8() << 8) | read_u8(); // } // // public long read_u32() throws IOException { // // FIXME: this is most definitely broken // return (read_u8() << 24) | (read_u8() << 16) | (read_u8() << 8) // | read_u8(); // } // // public int read_un(int n) throws IOException { // int value = 0; // int mask = 1; // for(int i=0;i!=n;++i) { // if(read_bit()) { // value |= mask; // } // mask = mask << 1; // } // return value; // } // // public int read_uv() throws IOException { // int value = 0; // boolean flag = true; // int shift = 0; // while(flag) { // int w = read_un(4); // flag = (w&8) != 0; // value = ((w&7)<<shift) | value; // shift = shift + 3; // } // return value; // } // // public boolean read_bit() throws IOException { // if(count == 0) { // value = input.read(); // if(value < 0) { throw new EOFException(); } // count = 8; // } // boolean r = (value&1) != 0; // value = value >> 1; // count = count - 1; // return r; // } // // public void pad_u8() throws IOException { // count = 0; // easy!! // } // } // Path: src/main/java/jasm/io/ClassFileReader.java import java.io.*; import java.util.*; import jasm.attributes.*; import jasm.io.BinaryInputStream; import jasm.lang.*; import jasm.util.*; int len = read_i4(index + 2); r.add(parseAttribute(index, enclosingMethod, enclosingClass)); index += len + 6; } return r; } protected BytecodeAttribute parseAttribute(int offset, ClassFile.Method enclosingMethod, ClassFile enclosingClass) { String name = getString(read_u2(offset)); if (name.equals("Code")) { return parseCode(offset, name, enclosingMethod); } else if (name.equals("Exceptions")) { return parseExceptions(offset, name); } else if (name.equals("InnerClasses")) { return parseInnerClasses(offset, name, enclosingClass.type()); } else if (name.equals("ConstantValue")) { return parseConstantValue(offset, name); } int len = read_i4(offset + 2) + 6; byte[] bs = new byte[len]; for (int i = 0; i != len; ++i) { bs[i] = bytes[offset + i]; } BytecodeAttribute.Reader reader = attributeReaders.get(name); if (reader != null) { try {
return reader.read(new BinaryInputStream(
Whiley/Jasm
src/main/java/jasm/verifier/ClassFileVerifier.java
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // }
import jasm.attributes.*; import jasm.lang.*; import jasm.util.Pair; import java.util.*;
// First, check no two identical labels for(Bytecode b : code.bytecodes()) { if(b instanceof Bytecode.Label) { Bytecode.Label lab = (Bytecode.Label) b; if(labels.contains(lab.name)) { // need better error reporting system. throw new IllegalArgumentException("Duplicate label \"" + lab.name + "\" in method " + method.name() + ", " + method.type()); } labels.add(lab.name); } } // Second, check every branch target exists for(Bytecode b : code.bytecodes()) { if(b instanceof Bytecode.Branch) { Bytecode.Branch br = (Bytecode.Branch) b; if(!labels.contains(br.label)){ throw new IllegalArgumentException("Unknown branch target \"" + br.label + "\" in method " + method.name() + ", " + method.type()); } } else if(b instanceof Bytecode.Switch) { Bytecode.Switch sw = (Bytecode.Switch) b; if(!labels.contains(sw.defaultLabel)){ throw new IllegalArgumentException("Unknown branch target \"" + sw.defaultLabel + "\" in method " + method.name() + ", " + method.type()); }
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // } // Path: src/main/java/jasm/verifier/ClassFileVerifier.java import jasm.attributes.*; import jasm.lang.*; import jasm.util.Pair; import java.util.*; // First, check no two identical labels for(Bytecode b : code.bytecodes()) { if(b instanceof Bytecode.Label) { Bytecode.Label lab = (Bytecode.Label) b; if(labels.contains(lab.name)) { // need better error reporting system. throw new IllegalArgumentException("Duplicate label \"" + lab.name + "\" in method " + method.name() + ", " + method.type()); } labels.add(lab.name); } } // Second, check every branch target exists for(Bytecode b : code.bytecodes()) { if(b instanceof Bytecode.Branch) { Bytecode.Branch br = (Bytecode.Branch) b; if(!labels.contains(br.label)){ throw new IllegalArgumentException("Unknown branch target \"" + br.label + "\" in method " + method.name() + ", " + method.type()); } } else if(b instanceof Bytecode.Switch) { Bytecode.Switch sw = (Bytecode.Switch) b; if(!labels.contains(sw.defaultLabel)){ throw new IllegalArgumentException("Unknown branch target \"" + sw.defaultLabel + "\" in method " + method.name() + ", " + method.type()); }
for(Pair<Integer,String> c : sw.cases) {
Whiley/Jasm
src/main/java/jasm/lang/JvmType.java
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // }
import jasm.util.Pair; import java.util.*;
return false; } public int hashCode() { return 1 + element.hashCode(); } public int compareTo(JvmType t) { if (t instanceof JvmType.Array) { return element.compareTo(((JvmType.Array) t).element()); } else if (t instanceof JvmType.Primitive) { return 1; } else { return -1; } } public List<JvmType.Variable> usedVariables() { return element.usedVariables(); } } /** * This represents a reference to a class. E.g. java.lang.String * * @author David J. Pearce * */ public static class Clazz implements Reference { private final String pkg;
// Path: src/main/java/jasm/util/Pair.java // public class Pair<FIRST,SECOND> { // protected final FIRST first; // protected final SECOND second; // // public Pair(FIRST f, SECOND s) { // first=f; // second=s; // } // // public FIRST first() { return first; } // public SECOND second() { return second; } // // public int hashCode() { // int fhc = first == null ? 0 : first.hashCode(); // int shc = second == null ? 0 : second.hashCode(); // return fhc ^ shc; // } // // public boolean equals(Object o) { // if(o instanceof Pair) { // Pair<FIRST, SECOND> p = (Pair<FIRST, SECOND>) o; // boolean r = false; // if(first != null) { r = first.equals(p.first()); } // else { r = p.first() == first; } // if(second != null) { r &= second.equals(p.second()); } // else { r &= p.second() == second; } // return r; // } // return false; // } // // public String toString() { // String fstr = first != null ? first.toString() : "null"; // String sstr = second != null ? second.toString() : "null"; // return "(" + fstr + ", " + sstr + ")"; // } // } // Path: src/main/java/jasm/lang/JvmType.java import jasm.util.Pair; import java.util.*; return false; } public int hashCode() { return 1 + element.hashCode(); } public int compareTo(JvmType t) { if (t instanceof JvmType.Array) { return element.compareTo(((JvmType.Array) t).element()); } else if (t instanceof JvmType.Primitive) { return 1; } else { return -1; } } public List<JvmType.Variable> usedVariables() { return element.usedVariables(); } } /** * This represents a reference to a class. E.g. java.lang.String * * @author David J. Pearce * */ public static class Clazz implements Reference { private final String pkg;
private final List<Pair<String, List<JvmType.Reference>>> components;
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Message.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
import java.net.URLEncoder; import java.util.ArrayList; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.method.ScrollingMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType;
package fr.xtof54.jsgo; public class Message { private final static String cmdGetListOfMessages = "quick_do.php?obj=message&cmd=list&filter_folders=2&with=user_id"; private static GoJsActivity c; private static JSONArray headers, jsonmsgs; private static int curmsg=0; private static ArrayList<Message> messages = new ArrayList<Message>(); public int getMessageId() {return msgid;} public static void send(final ServerConnection server, final GoJsActivity main) { c=main; class EditMsgDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because it's going in the dialog layout final View msgview = inflater.inflate(R.layout.editmsg, null); builder.setView(msgview); builder.setPositiveButton("send", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EditMsgDialogFragment.this.getDialog().dismiss(); TextView t = (TextView)msgview.findViewById(R.id.editMsgTo); String touser = t.getText().toString(); t = (TextView)msgview.findViewById(R.id.editMsgSubj); String subj = t.getText().toString(); t = (TextView)msgview.findViewById(R.id.editMsgTxt); String txt = t.getText().toString(); String cmd = "quick_do.php?obj=message&cmd=send_msg&ouser="+ URLEncoder.encode(touser)+"&msg="+ URLEncoder.encode(txt)+"&subj="+ URLEncoder.encode(subj);
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // Path: src/fr/xtof54/jsgo/Message.java import java.net.URLEncoder; import java.util.ArrayList; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.text.method.ScrollingMovementMethod; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; package fr.xtof54.jsgo; public class Message { private final static String cmdGetListOfMessages = "quick_do.php?obj=message&cmd=list&filter_folders=2&with=user_id"; private static GoJsActivity c; private static JSONArray headers, jsonmsgs; private static int curmsg=0; private static ArrayList<Message> messages = new ArrayList<Message>(); public int getMessageId() {return msgid;} public static void send(final ServerConnection server, final GoJsActivity main) { c=main; class EditMsgDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because it's going in the dialog layout final View msgview = inflater.inflate(R.layout.editmsg, null); builder.setView(msgview); builder.setPositiveButton("send", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EditMsgDialogFragment.this.getDialog().dismiss(); TextView t = (TextView)msgview.findViewById(R.id.editMsgTo); String touser = t.getText().toString(); t = (TextView)msgview.findViewById(R.id.editMsgSubj); String subj = t.getText().toString(); t = (TextView)msgview.findViewById(R.id.editMsgTxt); String txt = t.getText().toString(); String cmd = "quick_do.php?obj=message&cmd=send_msg&ouser="+ URLEncoder.encode(touser)+"&msg="+ URLEncoder.encode(txt)+"&subj="+ URLEncoder.encode(subj);
server.sendCmdToServer(cmd, eventType.msgSendStart, eventType.msgSendEnd);
cerisara/DragonGoApp
src/rene/util/xml/XmlReader.java
// Path: src/rene/util/SimpleStringBuffer.java // public class SimpleStringBuffer // { private int Size,N; // private char Buf[]; // public SimpleStringBuffer (int size) // { Size=size; // Buf=new char[size]; // N=0; // } // public SimpleStringBuffer (char b[]) // { Size=b.length; // Buf=b; // N=0; // } // public void append (char c) // { if (N<Size) Buf[N++]=c; // else // { Size=2*Size; // char NewBuf[]=new char[Size]; // for (int i=0; i<N; i++) NewBuf[i]=Buf[i]; // Buf=NewBuf; // Buf[N++]=c; // } // } // public void append (String s) // { int n=s.length(); // for (int i=0; i<n; i++) append(s.charAt(i)); // } // public void clear () // { N=0; // } // public String toString () // { if (N==0) return ""; // return new String(Buf,0,N); // } // }
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import rene.util.SimpleByteBuffer; import rene.util.SimpleStringBuffer; import rene.util.list.ListElement;
package rene.util.xml; public class XmlReader { BufferedReader In;
// Path: src/rene/util/SimpleStringBuffer.java // public class SimpleStringBuffer // { private int Size,N; // private char Buf[]; // public SimpleStringBuffer (int size) // { Size=size; // Buf=new char[size]; // N=0; // } // public SimpleStringBuffer (char b[]) // { Size=b.length; // Buf=b; // N=0; // } // public void append (char c) // { if (N<Size) Buf[N++]=c; // else // { Size=2*Size; // char NewBuf[]=new char[Size]; // for (int i=0; i<N; i++) NewBuf[i]=Buf[i]; // Buf=NewBuf; // Buf[N++]=c; // } // } // public void append (String s) // { int n=s.length(); // for (int i=0; i<n; i++) append(s.charAt(i)); // } // public void clear () // { N=0; // } // public String toString () // { if (N==0) return ""; // return new String(Buf,0,N); // } // } // Path: src/rene/util/xml/XmlReader.java import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import rene.util.SimpleByteBuffer; import rene.util.SimpleStringBuffer; import rene.util.list.ListElement; package rene.util.xml; public class XmlReader { BufferedReader In;
SimpleStringBuffer buf=new SimpleStringBuffer(10000);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Reviews.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLDecoder; import java.util.ArrayList; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.res.AssetManager; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;
class DetListDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // sgfs should never be empty, because this list can only be displayed *after* contReview() ArrayAdapter<String> adapter = new ArrayAdapter<String>(GoJsActivity.main, R.layout.detlistitem, sgfs); // Inflate and set the layout for the dialog // Pass null as the parent view because it's going in the dialog layout View listFrameview = inflater.inflate(R.layout.ladder, null); { TextView ladderlab = (TextView)listFrameview.findViewById(R.id.ladderlab); String s = "Choose the file to review:"; ladderlab.setText(s); } final ListView ladder = (ListView)listFrameview.findViewById(R.id.ladderList); ladder.setAdapter(adapter); ladder.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { tmpchosen = position; } }); builder.setView(listFrameview); builder.setPositiveButton("Review", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DetListDialogFragment.this.getDialog().dismiss(); if (tmpchosen<0) {
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums}; // Path: src/fr/xtof54/jsgo/Reviews.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLDecoder; import java.util.ArrayList; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.res.AssetManager; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; class DetListDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // sgfs should never be empty, because this list can only be displayed *after* contReview() ArrayAdapter<String> adapter = new ArrayAdapter<String>(GoJsActivity.main, R.layout.detlistitem, sgfs); // Inflate and set the layout for the dialog // Pass null as the parent view because it's going in the dialog layout View listFrameview = inflater.inflate(R.layout.ladder, null); { TextView ladderlab = (TextView)listFrameview.findViewById(R.id.ladderlab); String s = "Choose the file to review:"; ladderlab.setText(s); } final ListView ladder = (ListView)listFrameview.findViewById(R.id.ladderList); ladder.setAdapter(adapter); ladder.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { tmpchosen = position; } }); builder.setView(listFrameview); builder.setPositiveButton("Review", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DetListDialogFragment.this.getDialog().dismiss(); if (tmpchosen<0) {
EventManager.getEventManager().sendEvent(eventType.showMessage, "No sgf selected");
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Reviews.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLDecoder; import java.util.ArrayList; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.res.AssetManager; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener;
if (tmpchosen<0) { EventManager.getEventManager().sendEvent(eventType.showMessage, "No sgf selected"); } else { cursgf = tmpchosen; curmove = 0; saveCurReview(); contReviews(); } } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DetListDialogFragment.this.getDialog().dismiss(); } }); return builder.create(); } } tmpchosen=-1; final DetListDialogFragment msgdialog = new DetListDialogFragment(); msgdialog.show(GoJsActivity.main.getSupportFragmentManager(),"reviews"); } public static void saveCurReview() { System.out.println("save review pos "+cursgf+" "+curmove); PrefUtils.saveToPrefs(GoJsActivity.main, "REVIEWSGF", cursgf); PrefUtils.saveToPrefs(GoJsActivity.main, "REVIEWMOVE", curmove); } public static void contReviews() {
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums}; // Path: src/fr/xtof54/jsgo/Reviews.java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLDecoder; import java.util.ArrayList; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.content.res.AssetManager; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; if (tmpchosen<0) { EventManager.getEventManager().sendEvent(eventType.showMessage, "No sgf selected"); } else { cursgf = tmpchosen; curmove = 0; saveCurReview(); contReviews(); } } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DetListDialogFragment.this.getDialog().dismiss(); } }); return builder.create(); } } tmpchosen=-1; final DetListDialogFragment msgdialog = new DetListDialogFragment(); msgdialog.show(GoJsActivity.main.getSupportFragmentManager(),"reviews"); } public static void saveCurReview() { System.out.println("save review pos "+cursgf+" "+curmove); PrefUtils.saveToPrefs(GoJsActivity.main, "REVIEWSGF", cursgf); PrefUtils.saveToPrefs(GoJsActivity.main, "REVIEWMOVE", curmove); } public static void contReviews() {
GoJsActivity.main.changeState(guistate.review);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Ladder.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Calendar; import fr.xtof54.jsgo.EventManager.eventType;
if (j<0) { k=0; break; } k=s.indexOf("</tr",j); if (k<0) { // there is the beginning but not the end firsthalf=s.substring(j); break; } else { treatLine(s.substring(j, k)); } i=k; } if (k==0) { // no beginning in the current string; we can start over with the next s } else if (k<0) { // only the first half; we have to complete } } f.close(); } catch (IOException e) { e.printStackTrace(); } userList = new String[reslist.size()]; reslist.toArray(userList); ridList = new String[reslist.size()]; rids.toArray(ridList); saveList(); System.out.println("end ladder to array: "+ridList.length+" "+userList.length); if (userList.length==0) {
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // Path: src/fr/xtof54/jsgo/Ladder.java import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.net.URLDecoder; import java.util.ArrayList; import java.util.Calendar; import fr.xtof54.jsgo.EventManager.eventType; if (j<0) { k=0; break; } k=s.indexOf("</tr",j); if (k<0) { // there is the beginning but not the end firsthalf=s.substring(j); break; } else { treatLine(s.substring(j, k)); } i=k; } if (k==0) { // no beginning in the current string; we can start over with the next s } else if (k<0) { // only the first half; we have to complete } } f.close(); } catch (IOException e) { e.printStackTrace(); } userList = new String[reslist.size()]; reslist.toArray(userList); ridList = new String[reslist.size()]; rids.toArray(ridList); saveList(); System.out.println("end ladder to array: "+ridList.length+" "+userList.length); if (userList.length==0) {
EventManager.getEventManager().sendEvent(eventType.showMessage, "you cannot challenge anymore in this ladder");
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Game.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashSet; import java.util.HashSet; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate;
* Called after a local game has been selected in the list of local games * * @param sgffile * @param gid */ static void savedGameChosen(final File sgffile, final int gid) { class ConfirmDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout View v = inflater.inflate(R.layout.error, null); // Add action buttons builder.setView(v).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ConfirmDialogFragment.this.getDialog().cancel(); } }) .setPositiveButton("Show", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Game g = new Game(null, gid ); g.loadSGFLocally(); g.prepareGame(); ConfirmDialogFragment.this.getDialog().cancel(); GUI.getGUI().showHome(); GoJsActivity.main.showGame(g);
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums}; // Path: src/fr/xtof54/jsgo/Game.java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashSet; import java.util.HashSet; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; * Called after a local game has been selected in the list of local games * * @param sgffile * @param gid */ static void savedGameChosen(final File sgffile, final int gid) { class ConfirmDialogFragment extends DialogFragment { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout View v = inflater.inflate(R.layout.error, null); // Add action buttons builder.setView(v).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ConfirmDialogFragment.this.getDialog().cancel(); } }) .setPositiveButton("Show", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Game g = new Game(null, gid ); g.loadSGFLocally(); g.prepareGame(); ConfirmDialogFragment.this.getDialog().cancel(); GUI.getGUI().showHome(); GoJsActivity.main.showGame(g);
GoJsActivity.main.changeState(guistate.play);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Game.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashSet; import java.util.HashSet; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate;
} }); if (savedGames!=null) { for (File f: savedGames) { int i=Integer.parseInt(f.getName().substring(6, f.getName().length()-4)); games.add(i); } } int[] gs = new int[games.size()]; int j=0; for (int i:games) gs[j++]=i; return gs; } public static void loadStatusGames(final ServerConnection server) { Thread push = new Thread(new Runnable() { @Override public void run() { final EventManager em = EventManager.getEventManager(); if (GoJsActivity.main.getGamesFromDGS) { System.out.println("DGSAPP loadstatusgame DGS "); // this listener will be called when list if downloaded EventManager.EventListener f = new EventManager.EventListener() { @Override public synchronized void reactToEvent() { JSONObject o = server.o; parseJSONStatusGames(o); // also connects now to the client server to give it time to connect correctly // if (games2play.size() > 0) WSclient.init(games2play.get(0).myid); System.out.println("DGSAPP end of loadstatusgame, unregistering listener " + games2play.size());
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums}; // Path: src/fr/xtof54/jsgo/Game.java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.ArrayList; import java.util.HashSet; import java.util.HashSet; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.GoJsActivity.guistate; } }); if (savedGames!=null) { for (File f: savedGames) { int i=Integer.parseInt(f.getName().substring(6, f.getName().length()-4)); games.add(i); } } int[] gs = new int[games.size()]; int j=0; for (int i:games) gs[j++]=i; return gs; } public static void loadStatusGames(final ServerConnection server) { Thread push = new Thread(new Runnable() { @Override public void run() { final EventManager em = EventManager.getEventManager(); if (GoJsActivity.main.getGamesFromDGS) { System.out.println("DGSAPP loadstatusgame DGS "); // this listener will be called when list if downloaded EventManager.EventListener f = new EventManager.EventListener() { @Override public synchronized void reactToEvent() { JSONObject o = server.o; parseJSONStatusGames(o); // also connects now to the client server to give it time to connect correctly // if (games2play.size() > 0) WSclient.init(games2play.get(0).myid); System.out.println("DGSAPP end of loadstatusgame, unregistering listener " + games2play.size());
em.unregisterListener(eventType.downloadListEnd, this);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/ServerConnection.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.json.JSONObject; import android.util.Log; import fr.xtof54.jsgo.EventManager.eventType;
* creates a connection to a specific server; * determines the correct credentials * @param num */ public ServerConnection(int num, String userlogin, String userpwd) { server=serverNames[num]; // TODO: this must be handled outside of this class // String tu = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_USERNAME_KEY,null); // String tp = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_PASSWORD_KEY,null); // if (tu==null||tp==null) { // logger.showMsg("Please enter your credentials first via menu Settings"); // return; // } // if (GoJsActivity.main.debugdevel==0) { // GoJsActivity.main.debugdevel=1; // } else if (GoJsActivity.main.debugdevel==1) { // tu = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_USERNAME2_KEY,null); // tp = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_PASSWORD2_KEY,null); // GoJsActivity.main.debugdevel=0; // } u=userlogin; p=userpwd; } /** * Login to this server * WARNING: asynchronous / non-blocking !! */ public boolean loginok=false; public void startLogin() { final EventManager em = EventManager.getEventManager();
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // Path: src/fr/xtof54/jsgo/ServerConnection.java import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.json.JSONObject; import android.util.Log; import fr.xtof54.jsgo.EventManager.eventType; * creates a connection to a specific server; * determines the correct credentials * @param num */ public ServerConnection(int num, String userlogin, String userpwd) { server=serverNames[num]; // TODO: this must be handled outside of this class // String tu = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_USERNAME_KEY,null); // String tp = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_PASSWORD_KEY,null); // if (tu==null||tp==null) { // logger.showMsg("Please enter your credentials first via menu Settings"); // return; // } // if (GoJsActivity.main.debugdevel==0) { // GoJsActivity.main.debugdevel=1; // } else if (GoJsActivity.main.debugdevel==1) { // tu = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_USERNAME2_KEY,null); // tp = PrefUtils.getFromPrefs(GoJsActivity.main, PrefUtils.PREFS_LOGIN_PASSWORD2_KEY,null); // GoJsActivity.main.debugdevel=0; // } u=userlogin; p=userpwd; } /** * Login to this server * WARNING: asynchronous / non-blocking !! */ public boolean loginok=false; public void startLogin() { final EventManager em = EventManager.getEventManager();
em.sendEvent(eventType.loginStarted);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/GoJsActivity.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/ServerConnection.java // public interface DetLogger { // public void showMsg(String s); // }
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; import org.json.JSONException; import org.json.JSONObject; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.ServerConnection.DetLogger; import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Environment; import android.os.Handler; import android.os.Process; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.AssetManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.WebChromeClient; import android.webkit.ConsoleMessage; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.MotionEvent;
GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"TW\",\""+coords+"\")"); } GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()"); } catch (JSONException e) { e.printStackTrace(); showMessage("warning: error counting"); } return sc; } /** * we remove all territories and X in the goban but not in the sgf, * because we'll need them to compute the "toggled dead stones" to estimate the score * we then add back the X from the server onto the goban, so that the user knows which stones were * marked dead and he can modify them. It should also make the toggle computing easier */ void cleanTerritory() { GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detsoncleanT()"); Game g = Game.gameShown; String serverMarkedStones = g.deadstInSgf; System.out.println("clean territory: serverMarkedStones: "+serverMarkedStones); for (int i=0;i<serverMarkedStones.length();i+=2) { String coord = serverMarkedStones.substring(i,i+2); GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"MA\", \""+coord+"\")"); } GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()"); } void copyEidogo(final String edir, final File odir) {
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/ServerConnection.java // public interface DetLogger { // public void showMsg(String s); // } // Path: src/fr/xtof54/jsgo/GoJsActivity.java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; import org.json.JSONException; import org.json.JSONObject; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.ServerConnection.DetLogger; import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Environment; import android.os.Handler; import android.os.Process; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.AssetManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.WebChromeClient; import android.webkit.ConsoleMessage; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.MotionEvent; GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"TW\",\""+coords+"\")"); } GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()"); } catch (JSONException e) { e.printStackTrace(); showMessage("warning: error counting"); } return sc; } /** * we remove all territories and X in the goban but not in the sgf, * because we'll need them to compute the "toggled dead stones" to estimate the score * we then add back the X from the server onto the goban, so that the user knows which stones were * marked dead and he can modify them. It should also make the toggle computing easier */ void cleanTerritory() { GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].detsoncleanT()"); Game g = Game.gameShown; String serverMarkedStones = g.deadstInSgf; System.out.println("clean territory: serverMarkedStones: "+serverMarkedStones); for (int i=0;i<serverMarkedStones.length();i+=2) { String coord = serverMarkedStones.substring(i,i+2); GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].cursor.node.pushProperty(\"MA\", \""+coord+"\")"); } GoJsActivity.viewUrl("javascript:eidogo.autoPlayers[0].refresh()"); } void copyEidogo(final String edir, final File odir) {
EventManager.getEventManager().sendEvent(eventType.copyEidogoStart);
cerisara/DragonGoApp
src/fr/xtof54/jsgo/GoJsActivity.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/ServerConnection.java // public interface DetLogger { // public void showMsg(String s); // }
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; import org.json.JSONException; import org.json.JSONObject; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.ServerConnection.DetLogger; import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Environment; import android.os.Handler; import android.os.Process; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.AssetManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.WebChromeClient; import android.webkit.ConsoleMessage; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.MotionEvent;
} return u+" "+p; } boolean initServer() { System.out.println("call initserver "+server); if (server!=null) return true; String loginkey = PrefUtils.PREFS_LOGIN_USERNAME_KEY; String pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD_KEY; if (chosenLogin==1) { loginkey = PrefUtils.PREFS_LOGIN_USERNAME2_KEY; pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD2_KEY; } String u = PrefUtils.getFromPrefs(this, loginkey ,null); String p = PrefUtils.getFromPrefs(this, pwdkey ,null); System.out.println("credsdebug "+u+" "+p+" "+chosenLogin); if (u==null||p==null) { showMessage("Please enter your credentials first via menu Settings"); return false; } { int i=PrefUtils.getFromPrefs(getApplicationContext(), PrefUtils.PREFS_BADNWIDTH_MODE, Game.ALWAYS_DOWNLOAD_SGF); Game.bandwidthMode=i; if (i==Game.PREFER_LOCAL_SGF) System.out.println("Set prefer local sgf from saved preferences"); } final GoJsActivity m = this; System.out.println("credentials passed to server "+u+" "+p); if (server==null) { server = new ServerConnection(chosenServer, u, p);
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // // Path: src/fr/xtof54/jsgo/ServerConnection.java // public interface DetLogger { // public void showMsg(String s); // } // Path: src/fr/xtof54/jsgo/GoJsActivity.java import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.concurrent.ArrayBlockingQueue; import org.json.JSONException; import org.json.JSONObject; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.EventManager.eventType; import fr.xtof54.jsgo.ServerConnection.DetLogger; import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Environment; import android.os.Handler; import android.os.Process; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.AssetManager; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.WebChromeClient; import android.webkit.ConsoleMessage; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ListView; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.view.MotionEvent; } return u+" "+p; } boolean initServer() { System.out.println("call initserver "+server); if (server!=null) return true; String loginkey = PrefUtils.PREFS_LOGIN_USERNAME_KEY; String pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD_KEY; if (chosenLogin==1) { loginkey = PrefUtils.PREFS_LOGIN_USERNAME2_KEY; pwdkey = PrefUtils.PREFS_LOGIN_PASSWORD2_KEY; } String u = PrefUtils.getFromPrefs(this, loginkey ,null); String p = PrefUtils.getFromPrefs(this, pwdkey ,null); System.out.println("credsdebug "+u+" "+p+" "+chosenLogin); if (u==null||p==null) { showMessage("Please enter your credentials first via menu Settings"); return false; } { int i=PrefUtils.getFromPrefs(getApplicationContext(), PrefUtils.PREFS_BADNWIDTH_MODE, Game.ALWAYS_DOWNLOAD_SGF); Game.bandwidthMode=i; if (i==Game.PREFER_LOCAL_SGF) System.out.println("Set prefer local sgf from saved preferences"); } final GoJsActivity m = this; System.out.println("credentials passed to server "+u+" "+p); if (server==null) { server = new ServerConnection(chosenServer, u, p);
DetLogger l = new DetLogger() {
cerisara/DragonGoApp
src/fr/xtof54/jsgo/Forums.java
// Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums};
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.client.methods.HttpGet; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.GoJsActivity.guistate; import java.net.URLEncoder;
static void showForums(final List<String> cats) { GoJsActivity.main.runOnUiThread(new Runnable() { @Override public void run() { if (cats.size()==0) { GoJsActivity.main.showMessage("No new forums; repress to see all forums"); if (!showAll) switchShowNew(); return; } System.out.println("set Forum view"); GoJsActivity.main.setContentView(R.layout.forumcats); String[] c = new String[cats.size()]; for (int i=0;i<c.length;i++) c[i]=cats.get(i); ArrayAdapter<String> adapter = new ArrayAdapter<String>(GoJsActivity.main, R.layout.detlistitem, c); final ListView listFrameview = (ListView)GoJsActivity.main.findViewById(R.id.forumCatsList); listFrameview.setAdapter(adapter); listFrameview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { final int n=position; Thread forumcatthread = new Thread(new Runnable() { @Override public void run() { Forums.catChosen(n); } }); forumcatthread.start(); } });
// Path: src/fr/xtof54/jsgo/GoJsActivity.java // enum guistate {nogame, play, markDeadStones, checkScore, message, review, forums}; // Path: src/fr/xtof54/jsgo/Forums.java import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.http.client.methods.HttpGet; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import fr.xtof54.jsgo.R; import fr.xtof54.jsgo.GoJsActivity.guistate; import java.net.URLEncoder; static void showForums(final List<String> cats) { GoJsActivity.main.runOnUiThread(new Runnable() { @Override public void run() { if (cats.size()==0) { GoJsActivity.main.showMessage("No new forums; repress to see all forums"); if (!showAll) switchShowNew(); return; } System.out.println("set Forum view"); GoJsActivity.main.setContentView(R.layout.forumcats); String[] c = new String[cats.size()]; for (int i=0;i<c.length;i++) c[i]=cats.get(i); ArrayAdapter<String> adapter = new ArrayAdapter<String>(GoJsActivity.main, R.layout.detlistitem, c); final ListView listFrameview = (ListView)GoJsActivity.main.findViewById(R.id.forumCatsList); listFrameview.setAdapter(adapter); listFrameview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { final int n=position; Thread forumcatthread = new Thread(new Runnable() { @Override public void run() { Forums.catChosen(n); } }); forumcatthread.start(); } });
GoJsActivity.main.curstate=guistate.forums;
cerisara/DragonGoApp
src/fr/xtof54/jsgo/AndroidServerConnection.java
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd};
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.BufferedOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URLDecoder; import java.net.URLEncoder; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.HttpResponseException; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.protocol.ClientContext; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.json.JSONObject; import javax.net.ssl.HttpsURLConnection; import android.webkit.CookieManager; import fr.xtof54.jsgo.EventManager.eventType;
if (s==null) break; System.out.println("DGSAPP request answer "+s); sb.append(s); } res = sb.toString(); } else { System.out.println("DGSAPP saving res in file "+saveInFile); PrintWriter fout = new PrintWriter(new FileWriter(saveInFile)); for (;;) { String s = fin.readLine(); if (s==null) break; fout.print(s); } fout.close(); res=null; } fin.close(); GoJsActivity.main.updateTraffic(); return res; } },httpctxt); System.out.println("DGSAPP just after execute..."); } catch (Exception e) { e.printStackTrace(); GoJsActivity.main.updateTraffic(); } return res; } public void ladderChallenge(final String rid, final int pos) {
// Path: src/fr/xtof54/jsgo/EventManager.java // enum eventType {loginStarted, loginEnd, downloadListStarted, downloadListEnd, downloadListGamesEnd, downloadGameStarted, downloadGameEnd, GameOK, moveSentStart, moveSentEnd, gobanReady, // msgSendStart, msgSendEnd, ladderStart, ladderEnd, ladderChallengeStart, ladderChallengeEnd, showMessage, copyEidogoStart, copyEidogoEnd}; // Path: src/fr/xtof54/jsgo/AndroidServerConnection.java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.BufferedOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URLDecoder; import java.net.URLEncoder; import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; import org.apache.http.Header; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.HttpResponseException; import org.apache.http.client.ResponseHandler; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.protocol.ClientContext; import org.apache.http.impl.client.BasicCookieStore; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.BasicHttpParams; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.json.JSONObject; import javax.net.ssl.HttpsURLConnection; import android.webkit.CookieManager; import fr.xtof54.jsgo.EventManager.eventType; if (s==null) break; System.out.println("DGSAPP request answer "+s); sb.append(s); } res = sb.toString(); } else { System.out.println("DGSAPP saving res in file "+saveInFile); PrintWriter fout = new PrintWriter(new FileWriter(saveInFile)); for (;;) { String s = fin.readLine(); if (s==null) break; fout.print(s); } fout.close(); res=null; } fin.close(); GoJsActivity.main.updateTraffic(); return res; } },httpctxt); System.out.println("DGSAPP just after execute..."); } catch (Exception e) { e.printStackTrace(); GoJsActivity.main.updateTraffic(); } return res; } public void ladderChallenge(final String rid, final int pos) {
EventManager.getEventManager().sendEvent(eventType.ladderChallengeStart);
cerisara/DragonGoApp
src/fr/xtof54/sgfsearch/Node.java
// Path: src/rene/util/list/Tree.java // public class Tree // { ListClass Children; // list of children, each with Tree as content // Object Content; // content // ListElement Le; // the listelement containing the tree // Tree Parent; // the parent tree // // /** initialize with an object and no children */ // public Tree (Object o) // { Content=o; // Children=new ListClass(); // Le=null; Parent=null; // } // // /** add a child tree */ // public void addchild (Tree t) // { ListElement p=new ListElement(t); // Children.append(p); // t.Le=p; t.Parent=this; // } // // /** insert a child tree */ // public void insertchild (Tree t) // { if (!haschildren()) // simple case // { addchild(t); return; // } // // give t my children // t.Children=Children; // // make t my only child // Children=new ListClass(); // ListElement p=new ListElement(t); // Children.append(p); // t.Le=p; t.Parent=this; // // fix the parents of all grandchildren // ListElement le=t.Children.first(); // while (le!=null) // { Tree h=(Tree)(le.content()); // h.Parent=t; // le=le.next(); // } // } // // /** remove the specific child tree (must be in the tree!!!) */ // public void remove (Tree t) // { if (t.parent()!=this) return; // Children.remove(t.Le); // } // // /** remove all children */ // public void removeall () // { Children.removeall(); // } // // // Access Methods: // public boolean haschildren () { return Children.first()!=null; } // public Tree firstchild () { return (Tree)Children.first().content(); } // public Tree lastchild () { return (Tree)Children.last().content(); } // public Tree parent () { return Parent; } // public ListClass children () { return Children; } // public Object content () { return Content; } // public void content (Object o) { Content=o; } // public ListElement listelement () { return Le; } // }
import java.io.PrintWriter; import rene.util.list.ListClass; import rene.util.list.ListElement; import rene.util.list.Tree; import rene.util.xml.XmlWriter;
while (p!=null) { a=(Action)p.content(); a.print(xml,size,number); if (a.type().equals("B") || a.type().equals("W")) number++; p=p.next(); } xml.endTagNewLine("Node"); } /** remove all actions */ public void removeactions () { Actions=new ListClass(); } /** add a new change to this node */ public void addchange (Change c) { Changes.append(new ListElement(c)); } /** clear the list of changes */ public void clearchanges () { Changes.removeall(); } // modification methods: public void main (boolean m) { Main=m; } /** Set the Main flag @param Tree is the tree, which contains this node on root. */
// Path: src/rene/util/list/Tree.java // public class Tree // { ListClass Children; // list of children, each with Tree as content // Object Content; // content // ListElement Le; // the listelement containing the tree // Tree Parent; // the parent tree // // /** initialize with an object and no children */ // public Tree (Object o) // { Content=o; // Children=new ListClass(); // Le=null; Parent=null; // } // // /** add a child tree */ // public void addchild (Tree t) // { ListElement p=new ListElement(t); // Children.append(p); // t.Le=p; t.Parent=this; // } // // /** insert a child tree */ // public void insertchild (Tree t) // { if (!haschildren()) // simple case // { addchild(t); return; // } // // give t my children // t.Children=Children; // // make t my only child // Children=new ListClass(); // ListElement p=new ListElement(t); // Children.append(p); // t.Le=p; t.Parent=this; // // fix the parents of all grandchildren // ListElement le=t.Children.first(); // while (le!=null) // { Tree h=(Tree)(le.content()); // h.Parent=t; // le=le.next(); // } // } // // /** remove the specific child tree (must be in the tree!!!) */ // public void remove (Tree t) // { if (t.parent()!=this) return; // Children.remove(t.Le); // } // // /** remove all children */ // public void removeall () // { Children.removeall(); // } // // // Access Methods: // public boolean haschildren () { return Children.first()!=null; } // public Tree firstchild () { return (Tree)Children.first().content(); } // public Tree lastchild () { return (Tree)Children.last().content(); } // public Tree parent () { return Parent; } // public ListClass children () { return Children; } // public Object content () { return Content; } // public void content (Object o) { Content=o; } // public ListElement listelement () { return Le; } // } // Path: src/fr/xtof54/sgfsearch/Node.java import java.io.PrintWriter; import rene.util.list.ListClass; import rene.util.list.ListElement; import rene.util.list.Tree; import rene.util.xml.XmlWriter; while (p!=null) { a=(Action)p.content(); a.print(xml,size,number); if (a.type().equals("B") || a.type().equals("W")) number++; p=p.next(); } xml.endTagNewLine("Node"); } /** remove all actions */ public void removeactions () { Actions=new ListClass(); } /** add a new change to this node */ public void addchange (Change c) { Changes.append(new ListElement(c)); } /** clear the list of changes */ public void clearchanges () { Changes.removeall(); } // modification methods: public void main (boolean m) { Main=m; } /** Set the Main flag @param Tree is the tree, which contains this node on root. */
public void main (Tree p)
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/simulator/concurrent/LoadGenerator.java
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/logic/CodeOffloadRequest.java // public class CodeOffloadRequest implements Runnable { // // // //BubbleSort client; // MiniMaxRemote client; // // public void run() { // // Method invocation of the algorithm to execute remotely // // // //BubbleSort // // //client = new BubbleSort(0); // //client.sortFunction(); // // // client = new MiniMaxRemote(); // // /** // * Initial board // */ // /*int[][] board = {{-3, -5, -4, -2, -1, -4, -5, -3}, // {-6, -6, -6, -6, -6, -6, -6, -6}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {6, 6, 6, 6, 6, 6, 6, 6}, // {3, 5, 4, 2, 1, 4, 5, 3} // }; // */ // // /** // * Game in progress // */ // // int [][] board = {{0, -3, -4, -2, -1, -4, 0, -3}, // {0, 0, -6, -6, -6, 0, -6, -6}, // {-6, -6, 0, 0, 0, 0, 0, -5}, // {-5, 0, 0, 5, 0, 0, 0, 0}, // {0, 0, 6, 0, 6, -6, 0, 0}, // {6, 6, 0, 6, 0, 6, 0, 6}, // {0, 0, 0, 0, 0, 0, 6, 0}, // {3, 0, 0, 2, 1, 4, 5, 3} // }; // // int [] chess = new int[64]; // for (int i=0;i<8;i++) // for (int j=0;j<8;j++) // chess[j*8+i]=board[i][j]; // // // // float [] steps = client.minimax(chess, 4, false); // // // } // // // // // }
import cs.mc.ut.ee.logic.CodeOffloadRequest;
package cs.mc.ut.ee.simulator.concurrent; /* * author Huber Flores */ public class LoadGenerator { public void generateLoad(int users){ for (int i = 0; i<users; i++){
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/logic/CodeOffloadRequest.java // public class CodeOffloadRequest implements Runnable { // // // //BubbleSort client; // MiniMaxRemote client; // // public void run() { // // Method invocation of the algorithm to execute remotely // // // //BubbleSort // // //client = new BubbleSort(0); // //client.sortFunction(); // // // client = new MiniMaxRemote(); // // /** // * Initial board // */ // /*int[][] board = {{-3, -5, -4, -2, -1, -4, -5, -3}, // {-6, -6, -6, -6, -6, -6, -6, -6}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {6, 6, 6, 6, 6, 6, 6, 6}, // {3, 5, 4, 2, 1, 4, 5, 3} // }; // */ // // /** // * Game in progress // */ // // int [][] board = {{0, -3, -4, -2, -1, -4, 0, -3}, // {0, 0, -6, -6, -6, 0, -6, -6}, // {-6, -6, 0, 0, 0, 0, 0, -5}, // {-5, 0, 0, 5, 0, 0, 0, 0}, // {0, 0, 6, 0, 6, -6, 0, 0}, // {6, 6, 0, 6, 0, 6, 0, 6}, // {0, 0, 0, 0, 0, 0, 6, 0}, // {3, 0, 0, 2, 1, 4, 5, 3} // }; // // int [] chess = new int[64]; // for (int i=0;i<8;i++) // for (int j=0;j<8;j++) // chess[j*8+i]=board[i][j]; // // // // float [] steps = client.minimax(chess, 4, false); // // // } // // // // // } // Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/simulator/concurrent/LoadGenerator.java import cs.mc.ut.ee.logic.CodeOffloadRequest; package cs.mc.ut.ee.simulator.concurrent; /* * author Huber Flores */ public class LoadGenerator { public void generateLoad(int users){ for (int i = 0; i<users; i++){
new Thread(new CodeOffloadRequest()).start();
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/edu/ut/mobile/network/Pack.java
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java // public class ParametersSimulator { // // // public static double GenerateDouble(double min, double max){ // Random r = new Random(); // // double value = min + (max - min) * r.nextDouble(); // // return value; // // // } // // // public static int GenerateInts(int min, int max){ // Random r = new Random(); // // int value = r.nextInt(max-min) + min; // // return value; // // // } // // // // }
import java.io.Serializable; import java.util.ArrayList; import java.util.List; import cs.mc.ut.ee.utilities.ParametersSimulator;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package edu.ut.mobile.network; public class Pack implements Serializable{ private static final long serialVersionUID = 1; String functionName = null; Class stateType = null; Object state = null; Object[] paramValues = null; Class[] paramTypes = null; //Timestamps List<String> timestamps = new ArrayList<String>(); int accGroup = 0; double RTT = 0; double energy = 0; public Pack(String functionName, Class stateType, Object state, Object[] paramValues, Class[] FuncDTypes) { this.functionName = functionName; this.stateType = stateType; this.state = state; this.paramValues = paramValues; this.paramTypes = FuncDTypes; timestamps.add(System.currentTimeMillis()+",client1");
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java // public class ParametersSimulator { // // // public static double GenerateDouble(double min, double max){ // Random r = new Random(); // // double value = min + (max - min) * r.nextDouble(); // // return value; // // // } // // // public static int GenerateInts(int min, int max){ // Random r = new Random(); // // int value = r.nextInt(max-min) + min; // // return value; // // // } // // // // } // Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/edu/ut/mobile/network/Pack.java import java.io.Serializable; import java.util.ArrayList; import java.util.List; import cs.mc.ut.ee.utilities.ParametersSimulator; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package edu.ut.mobile.network; public class Pack implements Serializable{ private static final long serialVersionUID = 1; String functionName = null; Class stateType = null; Object state = null; Object[] paramValues = null; Class[] paramTypes = null; //Timestamps List<String> timestamps = new ArrayList<String>(); int accGroup = 0; double RTT = 0; double energy = 0; public Pack(String functionName, Class stateType, Object state, Object[] paramValues, Class[] FuncDTypes) { this.functionName = functionName; this.stateType = stateType; this.state = state; this.paramValues = paramValues; this.paramTypes = FuncDTypes; timestamps.add(System.currentTimeMillis()+",client1");
accGroup = ParametersSimulator.GenerateInts(0, 5);
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework-JVM/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/CodeResources.java
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // }
import java.util.List; import cs.mc.ut.ee.allocation.Surrogate;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.manager; /** * author Huber Flores */ public class CodeResources { String codeId; //portion of code
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // } // Path: Framework-JVM/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/CodeResources.java import java.util.List; import cs.mc.ut.ee.allocation.Surrogate; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.manager; /** * author Huber Flores */ public class CodeResources { String codeId; //portion of code
List<Surrogate> backEnd;
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework/Push-basedManager/CloudAllocator/src/cs/mc/ut/ee/cloud/data/DeploymentResources.java
// Path: Framework/Push-basedManager/CloudAllocator/src/cs/mc/ut/ee/cloud/commons/Utilities.java // public class Utilities { // // public static String deployment = "deployment.properties"; // // public static String defaultAttribute = "defaul"; // // // public static <T> void iterateList(List<T> list){ // Iterator<T> iterator = list.iterator(); // // while (iterator.hasNext()){ // System.out.println(iterator.next()); // } // } // // public static String getIPFromInterface(String ni) throws UnknownHostException, SocketException{ // // if (ni.equals("lo")){ // return InetAddress.getLocalHost().getHostAddress(); // } // // //other Network interfaces // Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces(); // for (; n.hasMoreElements();) // { // NetworkInterface e = n.nextElement(); // // if (e.getDisplayName().equals(ni)){ // return getIPAddress(e); // } // // // } // // return null; // } // // public static String getIPAddress(NetworkInterface e){ // Enumeration<InetAddress> a = e.getInetAddresses(); // for (; a.hasMoreElements();) // { // InetAddress addr = a.nextElement(); //IPv6 // addr = a.nextElement(); //IPv4 // // return addr.getHostAddress(); // // } // // return null; // } // // // }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; import cs.mc.ut.ee.cloud.commons.Utilities;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.cloud.data; /** * author Huber Flores */ public class DeploymentResources { public static DeploymentResources instance; private Properties props = new Properties(); private String imageId; private String key; private String cert; private String keyName; private String instanceType; private int minServers; private int maxServers; private double cpuLower; private double cpuUpper; private DeploymentResources(){ setup(); } public static synchronized DeploymentResources getInstance(){ if (instance==null){ instance = new DeploymentResources(); return instance; } return instance; } public void setup(){ try {
// Path: Framework/Push-basedManager/CloudAllocator/src/cs/mc/ut/ee/cloud/commons/Utilities.java // public class Utilities { // // public static String deployment = "deployment.properties"; // // public static String defaultAttribute = "defaul"; // // // public static <T> void iterateList(List<T> list){ // Iterator<T> iterator = list.iterator(); // // while (iterator.hasNext()){ // System.out.println(iterator.next()); // } // } // // public static String getIPFromInterface(String ni) throws UnknownHostException, SocketException{ // // if (ni.equals("lo")){ // return InetAddress.getLocalHost().getHostAddress(); // } // // //other Network interfaces // Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces(); // for (; n.hasMoreElements();) // { // NetworkInterface e = n.nextElement(); // // if (e.getDisplayName().equals(ni)){ // return getIPAddress(e); // } // // // } // // return null; // } // // public static String getIPAddress(NetworkInterface e){ // Enumeration<InetAddress> a = e.getInetAddresses(); // for (; a.hasMoreElements();) // { // InetAddress addr = a.nextElement(); //IPv6 // addr = a.nextElement(); //IPv4 // // return addr.getHostAddress(); // // } // // return null; // } // // // } // Path: Framework/Push-basedManager/CloudAllocator/src/cs/mc/ut/ee/cloud/data/DeploymentResources.java import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; import cs.mc.ut.ee.cloud.commons.Utilities; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.cloud.data; /** * author Huber Flores */ public class DeploymentResources { public static DeploymentResources instance; private Properties props = new Properties(); private String imageId; private String key; private String cert; private String keyName; private String instanceType; private int minServers; private int maxServers; private double cpuLower; private double cpuUpper; private DeploymentResources(){ setup(); } public static synchronized DeploymentResources getInstance(){ if (instance==null){ instance = new DeploymentResources(); return instance; } return instance; } public void setup(){ try {
props.load(new FileInputStream(Utilities.deployment));
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/FrontEnd.java
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // }
import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import cs.mc.ut.ee.allocation.Surrogate;
private synchronized boolean isStopped() { return this.isStopped; } public synchronized void stop(){ this.isStopped = true; try { this.serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Error closing server", e); } } private void openServerSocket() { try { this.serverSocket = new ServerSocket(this.serverPort); } catch (IOException e) { throw new RuntimeException("Cannot open port 6000", e); } } /** * * @param appName is the key to seach. It should be easily extended to support other filters, e.g., accelerationType * @return list of surrogates in which the app is present */ private Map<String,String> getResource(String appName){ AppResources app = findResources(appName);
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // } // Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/FrontEnd.java import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import cs.mc.ut.ee.allocation.Surrogate; private synchronized boolean isStopped() { return this.isStopped; } public synchronized void stop(){ this.isStopped = true; try { this.serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Error closing server", e); } } private void openServerSocket() { try { this.serverSocket = new ServerSocket(this.serverPort); } catch (IOException e) { throw new RuntimeException("Cannot open port 6000", e); } } /** * * @param appName is the key to seach. It should be easily extended to support other filters, e.g., accelerationType * @return list of surrogates in which the app is present */ private Map<String,String> getResource(String appName){ AppResources app = findResources(appName);
Surrogate surrogate = null;;
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/taskpool/BubbleSortRequest.java
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/logic/BubbleSort.java // public class BubbleSort extends CloudRemotable { // int x; // // public BubbleSort(int N){ // x = N; // } // // // public double localsortFunction(){ // int[] num = new int[x]; // Random r = new Random(); // for (int i = 0; i < num.length; i++) { // num[i] = r.nextInt(1000000); // } // long startTime = System.nanoTime( ); // int j; // boolean flag = true; // int temp; // // while (flag) { // flag = false; // for (j = 0; j < num.length - 1; j++) { // if (num[j] < num[j + 1]) // { // temp = num[j]; // num[j] = num[j + 1]; // num[j + 1] = temp; // flag = true; // } // } // } // // return ((System.nanoTime() - startTime)*1.0e-6); // // } // // public double sortFunction() { // Method toExecute; // Class<?>[] paramTypes = null; // Object[] paramValues = null; // double result; // // try{ // toExecute = this.getClass().getDeclaredMethod("localsortFunction", paramTypes); // Vector results = getCloudController().execute(toExecute,paramValues,this,this.getClass()); // if(results != null){ // result = (Double) results.get(0); // copyState(results.get(1)); // System.out.println("Remote result: " + result); // return result; // }else{ // result = localsortFunction(); // System.out.println("Local result: " + result); // return result; // } // } catch (SecurityException se){ // } catch (NoSuchMethodException ns){ // }catch (Throwable th){ // } // return localsortFunction(); // // } // // // // void copyState(Object state){ // BubbleSort localstate = (BubbleSort) state; // this.x = localstate.x; // } // }
import java.util.Random; import cs.mc.ut.ee.logic.BubbleSort;
package fi.cs.ubicomp.taskpool; public class BubbleSortRequest implements Runnable { private final String TAG = BubbleSortRequest.class.getCanonicalName();
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/logic/BubbleSort.java // public class BubbleSort extends CloudRemotable { // int x; // // public BubbleSort(int N){ // x = N; // } // // // public double localsortFunction(){ // int[] num = new int[x]; // Random r = new Random(); // for (int i = 0; i < num.length; i++) { // num[i] = r.nextInt(1000000); // } // long startTime = System.nanoTime( ); // int j; // boolean flag = true; // int temp; // // while (flag) { // flag = false; // for (j = 0; j < num.length - 1; j++) { // if (num[j] < num[j + 1]) // { // temp = num[j]; // num[j] = num[j + 1]; // num[j + 1] = temp; // flag = true; // } // } // } // // return ((System.nanoTime() - startTime)*1.0e-6); // // } // // public double sortFunction() { // Method toExecute; // Class<?>[] paramTypes = null; // Object[] paramValues = null; // double result; // // try{ // toExecute = this.getClass().getDeclaredMethod("localsortFunction", paramTypes); // Vector results = getCloudController().execute(toExecute,paramValues,this,this.getClass()); // if(results != null){ // result = (Double) results.get(0); // copyState(results.get(1)); // System.out.println("Remote result: " + result); // return result; // }else{ // result = localsortFunction(); // System.out.println("Local result: " + result); // return result; // } // } catch (SecurityException se){ // } catch (NoSuchMethodException ns){ // }catch (Throwable th){ // } // return localsortFunction(); // // } // // // // void copyState(Object state){ // BubbleSort localstate = (BubbleSort) state; // this.x = localstate.x; // } // } // Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/taskpool/BubbleSortRequest.java import java.util.Random; import cs.mc.ut.ee.logic.BubbleSort; package fi.cs.ubicomp.taskpool; public class BubbleSortRequest implements Runnable { private final String TAG = BubbleSortRequest.class.getCanonicalName();
BubbleSort task;
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/Controller.java
// Path: Framework/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/Commons.java // public class Commons { // // final static double fixInterArivalTime = 0.1; // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // }
import cs.mc.ut.ee.utilities.Commons; import cs.mc.ut.ee.utilities.SimulatorConfiguration; import cs.mc.ut.ee.utilities.WorkLoad;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.simulator.interarrival; public class Controller { /** * @author Huber Flores */ public static void main(String[] args) { // TODO Auto-generated method stub SimulatorConfiguration operation = new SimulatorConfiguration();
// Path: Framework/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/Commons.java // public class Commons { // // final static double fixInterArivalTime = 0.1; // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/Controller.java import cs.mc.ut.ee.utilities.Commons; import cs.mc.ut.ee.utilities.SimulatorConfiguration; import cs.mc.ut.ee.utilities.WorkLoad; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.simulator.interarrival; public class Controller { /** * @author Huber Flores */ public static void main(String[] args) { // TODO Auto-generated method stub SimulatorConfiguration operation = new SimulatorConfiguration();
Commons.mode = operation.getSimulatorMode();
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/Controller.java
// Path: Framework/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/Commons.java // public class Commons { // // final static double fixInterArivalTime = 0.1; // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // }
import cs.mc.ut.ee.utilities.Commons; import cs.mc.ut.ee.utilities.SimulatorConfiguration; import cs.mc.ut.ee.utilities.WorkLoad;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.simulator.interarrival; public class Controller { /** * @author Huber Flores */ public static void main(String[] args) { // TODO Auto-generated method stub SimulatorConfiguration operation = new SimulatorConfiguration(); Commons.mode = operation.getSimulatorMode(); int experimentalTime = 0; double interarrivalTime = 0; int numberOfUsers = 0; int numberOfGroups = 0; if (args.length>1){ experimentalTime = Integer.valueOf(args[0]); interarrivalTime = Double.parseDouble(args[1]); numberOfUsers = Integer.valueOf(args[2]); numberOfGroups = Integer.valueOf(args[3]); }else{ System.err.println("Missing parameters"); System.err.println ("param 1: experimental time, param 2: interarrival time, param 3: number of users, param 4: number of groups"); System.exit(0); }
// Path: Framework/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/utilities/Commons.java // public class Commons { // // final static double fixInterArivalTime = 0.1; // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/Controller.java import cs.mc.ut.ee.utilities.Commons; import cs.mc.ut.ee.utilities.SimulatorConfiguration; import cs.mc.ut.ee.utilities.WorkLoad; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.simulator.interarrival; public class Controller { /** * @author Huber Flores */ public static void main(String[] args) { // TODO Auto-generated method stub SimulatorConfiguration operation = new SimulatorConfiguration(); Commons.mode = operation.getSimulatorMode(); int experimentalTime = 0; double interarrivalTime = 0; int numberOfUsers = 0; int numberOfGroups = 0; if (args.length>1){ experimentalTime = Integer.valueOf(args[0]); interarrivalTime = Double.parseDouble(args[1]); numberOfUsers = Integer.valueOf(args[2]); numberOfGroups = Integer.valueOf(args[3]); }else{ System.err.println("Missing parameters"); System.err.println ("param 1: experimental time, param 2: interarrival time, param 3: number of users, param 4: number of groups"); System.exit(0); }
WorkLoad.getInstance().setNumberOfUsers(numberOfUsers);
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework-JVM/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/FrontEnd.java
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // }
import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import cs.mc.ut.ee.allocation.Surrogate;
private synchronized boolean isStopped() { return this.isStopped; } public synchronized void stop(){ this.isStopped = true; try { this.serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Error closing server", e); } } private void openServerSocket() { try { this.serverSocket = new ServerSocket(this.serverPort); } catch (IOException e) { throw new RuntimeException("Cannot open port 6000", e); } } /** * * @param codeId is the key to search. It should be easily extended to support other filters, e.g., accelerationType * @return list of surrogates in which the code is present */ private Map<String,String> getResource(String codeId){ CodeResources code = findResources(codeId);
// Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/allocation/Surrogate.java // public class Surrogate { // String jarFile; //code to reconstruct the request in each component of the system // // LinkedList<String> apkPool; //ports in which the app is listening // // String ipAddress; //surrogate address // // /* // *String accelerationType; //other attributes about the server can be defined // */ // // // public Surrogate(LinkedList<String> apkPool, String ipAddress, String jarFile){ // setApkPool(apkPool); // setSurrogateIP(ipAddress); // setJarFile(jarFile); // } // // public void setApkPool(LinkedList<String> apkPool){ // this.apkPool = apkPool; // } // // public void setSurrogateIP(String surrogateIP){ // this.ipAddress = surrogateIP; // // } // // public LinkedList<String> getApkPool(){ // return this.apkPool; // } // // public String getSurrogateIP(){ // return this.ipAddress; // } // // public String getJarFile(){ // return this.jarFile; // } // // // public void setJarFile(String jarFile){ // this.jarFile = jarFile; // } // // } // Path: Framework-JVM/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/FrontEnd.java import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Type; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import cs.mc.ut.ee.allocation.Surrogate; private synchronized boolean isStopped() { return this.isStopped; } public synchronized void stop(){ this.isStopped = true; try { this.serverSocket.close(); } catch (IOException e) { throw new RuntimeException("Error closing server", e); } } private void openServerSocket() { try { this.serverSocket = new ServerSocket(this.serverPort); } catch (IOException e) { throw new RuntimeException("Cannot open port 6000", e); } } /** * * @param codeId is the key to search. It should be easily extended to support other filters, e.g., accelerationType * @return list of surrogates in which the code is present */ private Map<String,String> getResource(String codeId){ CodeResources code = findResources(codeId);
Surrogate surrogate = null;;
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // }
import java.util.Random; import cs.mc.ut.ee.utilities.WorkLoad; import fi.cs.ubicomp.traces.DataTrace;
package cs.mc.ut.ee.utilities; public class ParametersSimulator { public static double GenerateDouble(double min, double max){ Random r = new Random(); double value = min + (max - min) * r.nextDouble(); return value; } public static int GenerateInts(int min, int max){ Random r = new Random(); int value = r.nextInt(max-min) + min; return value; } public static String[] getUser(){
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // } // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java import java.util.Random; import cs.mc.ut.ee.utilities.WorkLoad; import fi.cs.ubicomp.traces.DataTrace; package cs.mc.ut.ee.utilities; public class ParametersSimulator { public static double GenerateDouble(double min, double max){ Random r = new Random(); double value = min + (max - min) * r.nextDouble(); return value; } public static int GenerateInts(int min, int max){ Random r = new Random(); int value = r.nextInt(max-min) + min; return value; } public static String[] getUser(){
DataTrace user = WorkLoad.getInstance().getUser();
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // }
import java.util.Random; import cs.mc.ut.ee.utilities.WorkLoad; import fi.cs.ubicomp.traces.DataTrace;
package cs.mc.ut.ee.utilities; public class ParametersSimulator { public static double GenerateDouble(double min, double max){ Random r = new Random(); double value = min + (max - min) * r.nextDouble(); return value; } public static int GenerateInts(int min, int max){ Random r = new Random(); int value = r.nextInt(max-min) + min; return value; } public static String[] getUser(){
// Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java // public class WorkLoad { // // /** // * Traces mode // */ // // public static WorkLoad instance; // // LinkedList<DataTrace> users = null; // // private WorkLoad(){ // // } // // public static synchronized WorkLoad getInstance(){ // if (instance==null){ // instance = new WorkLoad(); // return instance; // } // // return instance; // } // // public void setUsersWorkLoad(List<DataTrace> users){ // this.users = (LinkedList<DataTrace>) users; // } // // // public DataTrace getUser(){ // if (users!=null){ // if (!users.isEmpty()){ // DataTrace user = users.removeFirst(); // return user; // } // } // // return null; // } // // /** // * Interarrival mode // */ // // private int numberOfUsers = 0; // private int numberOfGroups = 0; // // List<DataTrace> snapShot; // // public void setNumberOfUsers(int numberOfUsers){ // this.numberOfUsers = numberOfUsers; // } // // public int getNumberOfUsers(){ // return this.numberOfUsers; // } // // public void setAccelerationGroups(int numberOfGroups){ // this.numberOfGroups = numberOfGroups; // } // // public int getNumberOfGroups(){ // return this.numberOfGroups; // } // // public void generateSnapShot(){ // snapShot = new ArrayList<DataTrace>(); // for (int i=0; i<numberOfUsers; i++){ // //int acceleration = ParametersSimulator.getRandomNumber(numberOfGroups); //snapshot in time // int acceleration = 0; //everybody initiates in 0 // snapShot.add(new DataTrace(String.valueOf(i), "user"+i, String.valueOf(acceleration))); // } // } // // public DataTrace getSnapShotUser(){ // if (snapShot!=null){ // if (!snapShot.isEmpty()){ // int index = ParametersSimulator.getRandomNumber(snapShot.size()); // // DataTrace user = snapShot.get(index); // // return user; // } // } // // return null; // } // // // public void promoteSnapShotUser(int index, String id, String userId, String accGroup){ // snapShot.get(index).setIndex(Integer.valueOf(id)); // snapShot.get(index).setUserId(userId); // snapShot.get(index).setAccGroup(accGroup); // // } // // // public int getSnapShotUserIndex(String index){ // for (int i=0; i<snapShot.size(); i++){ // if (snapShot.get(i).getIndex() == Integer.valueOf(index)){ // return i; // } // } // // return 0; // } // // // // // // // // } // // Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // } // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/ParametersSimulator.java import java.util.Random; import cs.mc.ut.ee.utilities.WorkLoad; import fi.cs.ubicomp.traces.DataTrace; package cs.mc.ut.ee.utilities; public class ParametersSimulator { public static double GenerateDouble(double min, double max){ Random r = new Random(); double value = min + (max - min) * r.nextDouble(); return value; } public static int GenerateInts(int min, int max){ Random r = new Random(); int value = r.nextInt(max-min) + min; return value; } public static String[] getUser(){
DataTrace user = WorkLoad.getInstance().getUser();
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/LoadGenerator.java
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/logic/CodeOffloadRequest.java // public class CodeOffloadRequest implements Runnable { // // // //BubbleSort client; // MiniMaxRemote client; // // public void run() { // // Method invocation of the algorithm to execute remotely // // // //BubbleSort // // //client = new BubbleSort(0); // //client.sortFunction(); // // // client = new MiniMaxRemote(); // // /** // * Initial board // */ // /*int[][] board = {{-3, -5, -4, -2, -1, -4, -5, -3}, // {-6, -6, -6, -6, -6, -6, -6, -6}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {6, 6, 6, 6, 6, 6, 6, 6}, // {3, 5, 4, 2, 1, 4, 5, 3} // }; // */ // // /** // * Game in progress // */ // // int [][] board = {{0, -3, -4, -2, -1, -4, 0, -3}, // {0, 0, -6, -6, -6, 0, -6, -6}, // {-6, -6, 0, 0, 0, 0, 0, -5}, // {-5, 0, 0, 5, 0, 0, 0, 0}, // {0, 0, 6, 0, 6, -6, 0, 0}, // {6, 6, 0, 6, 0, 6, 0, 6}, // {0, 0, 0, 0, 0, 0, 6, 0}, // {3, 0, 0, 2, 1, 4, 5, 3} // }; // // int [] chess = new int[64]; // for (int i=0;i<8;i++) // for (int j=0;j<8;j++) // chess[j*8+i]=board[i][j]; // // // // float [] steps = client.minimax(chess, 4, false); // // // } // // // // // }
import cs.mc.ut.ee.logic.CodeOffloadRequest;
package cs.mc.ut.ee.simulator.interarrival; /* * author Huber Flores */ public class LoadGenerator { double time; public void generateLoad(int experimentalTime, double interarrivalTime){ //experimentalTime is minutes time = experimentalTime *60*1000; double startTime = System.currentTimeMillis(); while((System.currentTimeMillis() - startTime) < time){
// Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/logic/CodeOffloadRequest.java // public class CodeOffloadRequest implements Runnable { // // // //BubbleSort client; // MiniMaxRemote client; // // public void run() { // // Method invocation of the algorithm to execute remotely // // // //BubbleSort // // //client = new BubbleSort(0); // //client.sortFunction(); // // // client = new MiniMaxRemote(); // // /** // * Initial board // */ // /*int[][] board = {{-3, -5, -4, -2, -1, -4, -5, -3}, // {-6, -6, -6, -6, -6, -6, -6, -6}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {0, 0, 0, 0, 0, 0, 0, 0}, // {6, 6, 6, 6, 6, 6, 6, 6}, // {3, 5, 4, 2, 1, 4, 5, 3} // }; // */ // // /** // * Game in progress // */ // // int [][] board = {{0, -3, -4, -2, -1, -4, 0, -3}, // {0, 0, -6, -6, -6, 0, -6, -6}, // {-6, -6, 0, 0, 0, 0, 0, -5}, // {-5, 0, 0, 5, 0, 0, 0, 0}, // {0, 0, 6, 0, 6, -6, 0, 0}, // {6, 6, 0, 6, 0, 6, 0, 6}, // {0, 0, 0, 0, 0, 0, 6, 0}, // {3, 0, 0, 2, 1, 4, 5, 3} // }; // // int [] chess = new int[64]; // for (int i=0;i<8;i++) // for (int j=0;j<8;j++) // chess[j*8+i]=board[i][j]; // // // // float [] steps = client.minimax(chess, 4, false); // // // } // // // // // } // Path: Framework-JVM/Simulator/MobileOffloadSimulator/src/main/java/cs/mc/ut/ee/simulator/interarrival/LoadGenerator.java import cs.mc.ut.ee.logic.CodeOffloadRequest; package cs.mc.ut.ee.simulator.interarrival; /* * author Huber Flores */ public class LoadGenerator { double time; public void generateLoad(int experimentalTime, double interarrivalTime){ //experimentalTime is minutes time = experimentalTime *60*1000; double startTime = System.currentTimeMillis(); while((System.currentTimeMillis() - startTime) < time){
new Thread(new CodeOffloadRequest()).start();
mobile-cloud-computing/ScalingMobileCodeOffloading
Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/Activator.java
// Path: TracesSimulator/Loader/Simulator/src/main/java/edu/ut/mobile/network/NetInfo.java // public class NetInfo{ // // //public static byte[] IPAddress = {Integer.valueOf("54").byteValue(),Integer.valueOf("73").byteValue(),Integer.valueOf("28").byteValue(),Integer.valueOf("236").byteValue()}; // static byte[] IPAddress = {Integer.valueOf("10").byteValue(),Integer.valueOf("20").byteValue(),Integer.valueOf("207").byteValue(),Integer.valueOf("250").byteValue()}; // static int port = 6000; // static int waitTime = 100000; // // // // }
import edu.ut.mobile.network.NetInfo;
/* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.manager; /** * author Huber Flores */ public class Activator { public static void main(String[] args) {
// Path: TracesSimulator/Loader/Simulator/src/main/java/edu/ut/mobile/network/NetInfo.java // public class NetInfo{ // // //public static byte[] IPAddress = {Integer.valueOf("54").byteValue(),Integer.valueOf("73").byteValue(),Integer.valueOf("28").byteValue(),Integer.valueOf("236").byteValue()}; // static byte[] IPAddress = {Integer.valueOf("10").byteValue(),Integer.valueOf("20").byteValue(),Integer.valueOf("207").byteValue(),Integer.valueOf("250").byteValue()}; // static int port = 6000; // static int waitTime = 100000; // // // // } // Path: Framework/Manager/CodeOffload/src/main/java/cs/mc/ut/ee/manager/Activator.java import edu.ut.mobile.network.NetInfo; /* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Please send inquiries to huber AT ut DOT ee */ package cs.mc.ut.ee.manager; /** * author Huber Flores */ public class Activator { public static void main(String[] args) {
FrontEnd server = new FrontEnd(NetInfo.port);
mobile-cloud-computing/ScalingMobileCodeOffloading
TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java
// Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // }
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import fi.cs.ubicomp.traces.DataTrace;
package cs.mc.ut.ee.utilities; public class WorkLoad { /** * Traces mode */ public static WorkLoad instance;
// Path: TracesSimulator/Loader/Simulator/src/main/java/fi/cs/ubicomp/traces/DataTrace.java // public class DataTrace { // // private int index; // private String userId; // private String accGroup; // // public DataTrace(String index, String userId, String accGroup){ // this.index = Integer.parseInt(index); // this.userId = userId; // this.accGroup = accGroup; // } // // public int getIndex(){ // return this.index; // } // // public String getUserId(){ // return this.userId; // } // // public String getAccGroup(){ // return this.accGroup; // } // // // public void setIndex(int index){ // this.index = index; // } // // // public void setUserId(String userId){ // this.userId = userId; // } // // public void setAccGroup(String accGroup){ // this.accGroup = accGroup; // } // // } // Path: TracesSimulator/Loader/Simulator/src/main/java/cs/mc/ut/ee/utilities/WorkLoad.java import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import fi.cs.ubicomp.traces.DataTrace; package cs.mc.ut.ee.utilities; public class WorkLoad { /** * Traces mode */ public static WorkLoad instance;
LinkedList<DataTrace> users = null;
CSSE497/pathfinder-server
test/io/pathfinder/websockets/WebSocketActorTest.java
// Path: test/io/pathfinder/BaseAppTest.java // public class BaseAppTest { // public FakeApplication app; // public final Cluster cluster = new Cluster(); // public final Application PATHFINDER_APPLICATION = new Application(); // public static final String APPLICATION_ID = "001e7047-ee14-40d6-898a-5acf3a1cfd8a"; // public static final String CLUSTER_ID = APPLICATION_ID; // public static final String ROOT = "/root"; // // public Cluster baseCluster() { // return Cluster.finder().byId(CLUSTER_ID); // } // // @Before // public void startApp() { // Map<String,String> conf = new HashMap<>(Helpers.inMemoryDatabase()); // conf.put("Authenticate", "false"); // app = Helpers.fakeApplication(conf); // Helpers.start(app); // PATHFINDER_APPLICATION.id_$eq(APPLICATION_ID); // PATHFINDER_APPLICATION.name_$eq("MY COOL APP"); // cluster.id_$eq(CLUSTER_ID); // cluster.insert(); // cluster.id_$eq(CLUSTER_ID); // PATHFINDER_APPLICATION.insert(); // cluster.save(); // } // // @After // public void stopApp() { // Helpers.stop(app); // } // } // // Path: app/io/pathfinder/models/TransportStatus.java // public enum TransportStatus { // @EnumValue("0") // Offline, // @EnumValue("1") // Online; // // public static final Format<TransportStatus> format = new JavaEnumFormat<>(TransportStatus.class); // }
import akka.actor.ActorSystem; import akka.actor.Props; import akka.pattern.Patterns; import akka.testkit.TestActorRef; import akka.testkit.TestProbe; import io.pathfinder.BaseAppTest; import io.pathfinder.models.Cluster; import io.pathfinder.models.Commodity; import io.pathfinder.models.Transport; import io.pathfinder.models.TransportStatus; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import play.api.libs.json.JsNumber; import play.api.libs.json.JsObject; import play.api.libs.json.JsValue; import play.api.libs.json.Json; import scala.collection.mutable.HashMap; import scala.collection.mutable.Map; import scala.math.BigDecimal;
@Before public void initActor() { ActorSystem sys = ActorSystem.create(); client = new TestProbe(sys); final Props props = WebSocketActor.props(client.ref(), APPLICATION_ID); socket = TestActorRef.create(sys, props); } @Test public void testCreateCluster() throws Exception { final String PATH = ROOT + "/subcluster"; Patterns.ask(socket, WebSocketMessage.format().reads(JSON_CREATE_CLUSTER).get(), TIMEOUT); Cluster createdCluster = new Cluster(); createdCluster.id_$eq(PATH); client.expectMsg(new WebSocketMessage.Created( ModelTypes.Cluster(), Cluster.format().writes(createdCluster))); } @Test public void testCreateTransport() { final int NEXT_UNUSED_ID = 1; Patterns.ask(socket, WebSocketMessage.format().reads(JSON_CREATE_TRANSPORT).get(), TIMEOUT); Transport createdTransport = new Transport(); createdTransport.id_$eq(NEXT_UNUSED_ID); createdTransport.latitude_$eq(0.1); createdTransport.longitude_$eq(-12.3); Map<String,JsValue> meta = new HashMap<>(); meta.put("capacity", new JsNumber(BigDecimal.valueOf(99))); createdTransport.metadata_$eq(new JsObject(meta));
// Path: test/io/pathfinder/BaseAppTest.java // public class BaseAppTest { // public FakeApplication app; // public final Cluster cluster = new Cluster(); // public final Application PATHFINDER_APPLICATION = new Application(); // public static final String APPLICATION_ID = "001e7047-ee14-40d6-898a-5acf3a1cfd8a"; // public static final String CLUSTER_ID = APPLICATION_ID; // public static final String ROOT = "/root"; // // public Cluster baseCluster() { // return Cluster.finder().byId(CLUSTER_ID); // } // // @Before // public void startApp() { // Map<String,String> conf = new HashMap<>(Helpers.inMemoryDatabase()); // conf.put("Authenticate", "false"); // app = Helpers.fakeApplication(conf); // Helpers.start(app); // PATHFINDER_APPLICATION.id_$eq(APPLICATION_ID); // PATHFINDER_APPLICATION.name_$eq("MY COOL APP"); // cluster.id_$eq(CLUSTER_ID); // cluster.insert(); // cluster.id_$eq(CLUSTER_ID); // PATHFINDER_APPLICATION.insert(); // cluster.save(); // } // // @After // public void stopApp() { // Helpers.stop(app); // } // } // // Path: app/io/pathfinder/models/TransportStatus.java // public enum TransportStatus { // @EnumValue("0") // Offline, // @EnumValue("1") // Online; // // public static final Format<TransportStatus> format = new JavaEnumFormat<>(TransportStatus.class); // } // Path: test/io/pathfinder/websockets/WebSocketActorTest.java import akka.actor.ActorSystem; import akka.actor.Props; import akka.pattern.Patterns; import akka.testkit.TestActorRef; import akka.testkit.TestProbe; import io.pathfinder.BaseAppTest; import io.pathfinder.models.Cluster; import io.pathfinder.models.Commodity; import io.pathfinder.models.Transport; import io.pathfinder.models.TransportStatus; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import play.api.libs.json.JsNumber; import play.api.libs.json.JsObject; import play.api.libs.json.JsValue; import play.api.libs.json.Json; import scala.collection.mutable.HashMap; import scala.collection.mutable.Map; import scala.math.BigDecimal; @Before public void initActor() { ActorSystem sys = ActorSystem.create(); client = new TestProbe(sys); final Props props = WebSocketActor.props(client.ref(), APPLICATION_ID); socket = TestActorRef.create(sys, props); } @Test public void testCreateCluster() throws Exception { final String PATH = ROOT + "/subcluster"; Patterns.ask(socket, WebSocketMessage.format().reads(JSON_CREATE_CLUSTER).get(), TIMEOUT); Cluster createdCluster = new Cluster(); createdCluster.id_$eq(PATH); client.expectMsg(new WebSocketMessage.Created( ModelTypes.Cluster(), Cluster.format().writes(createdCluster))); } @Test public void testCreateTransport() { final int NEXT_UNUSED_ID = 1; Patterns.ask(socket, WebSocketMessage.format().reads(JSON_CREATE_TRANSPORT).get(), TIMEOUT); Transport createdTransport = new Transport(); createdTransport.id_$eq(NEXT_UNUSED_ID); createdTransport.latitude_$eq(0.1); createdTransport.longitude_$eq(-12.3); Map<String,JsValue> meta = new HashMap<>(); meta.put("capacity", new JsNumber(BigDecimal.valueOf(99))); createdTransport.metadata_$eq(new JsObject(meta));
createdTransport.status_$eq(TransportStatus.Online);
MinecraftForge/FML
src/main/java/net/minecraftforge/fml/common/LoadController.java
// Path: src/main/java/net/minecraftforge/fml/common/ProgressManager.java // @Deprecated // public static class ProgressBar // { // private final String title; // private final int steps; // private volatile int step = 0; // private volatile String message = ""; // // private ProgressBar(String title, int steps) // { // this.title = title; // this.steps = steps; // } // // public void step(Class<?> classToName, String... extra) // { // step(ClassNameUtils.shortName(classToName)+Joiner.on(' ').join(extra)); // } // // public void step(String message) // { // if(step >= steps) throw new IllegalStateException("too much steps for ProgressBar " + title); // step++; // this.message = message; // FMLCommonHandler.instance().processWindowMessages(); // } // // public String getTitle() // { // return title; // } // // public int getSteps() // { // return steps; // } // // public int getStep() // { // return step; // } // // public String getMessage() // { // return message; // } // } // // Path: src/main/java/net/minecraftforge/fml/common/event/FMLLoadEvent.java // public class FMLLoadEvent // { // // }
import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import net.minecraftforge.fml.common.LoaderState.ModState; import net.minecraftforge.fml.common.ProgressManager.ProgressBar; import net.minecraftforge.fml.common.event.FMLEvent; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModDisabledEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.ThreadContext; import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe;
private ModContainer activeContainer; private BiMap<ModContainer, Object> modObjectList; private ListMultimap<String, ModContainer> packageOwners; public LoadController(Loader loader) { this.loader = loader; this.masterChannel = new EventBus("FMLMainChannel"); this.masterChannel.register(this); state = LoaderState.NOINIT; packageOwners = ArrayListMultimap.create(); } void disableMod(ModContainer mod) { HashMap<String, EventBus> temporary = Maps.newHashMap(eventChannels); String modId = mod.getModId(); EventBus bus = temporary.remove(modId); bus.post(new FMLModDisabledEvent()); if (errors.get(modId).isEmpty()) { eventChannels = ImmutableMap.copyOf(temporary); modStates.put(modId, ModState.DISABLED); modObjectList.remove(mod); activeModList.remove(mod); } } @Subscribe
// Path: src/main/java/net/minecraftforge/fml/common/ProgressManager.java // @Deprecated // public static class ProgressBar // { // private final String title; // private final int steps; // private volatile int step = 0; // private volatile String message = ""; // // private ProgressBar(String title, int steps) // { // this.title = title; // this.steps = steps; // } // // public void step(Class<?> classToName, String... extra) // { // step(ClassNameUtils.shortName(classToName)+Joiner.on(' ').join(extra)); // } // // public void step(String message) // { // if(step >= steps) throw new IllegalStateException("too much steps for ProgressBar " + title); // step++; // this.message = message; // FMLCommonHandler.instance().processWindowMessages(); // } // // public String getTitle() // { // return title; // } // // public int getSteps() // { // return steps; // } // // public int getStep() // { // return step; // } // // public String getMessage() // { // return message; // } // } // // Path: src/main/java/net/minecraftforge/fml/common/event/FMLLoadEvent.java // public class FMLLoadEvent // { // // } // Path: src/main/java/net/minecraftforge/fml/common/LoadController.java import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import net.minecraftforge.fml.common.LoaderState.ModState; import net.minecraftforge.fml.common.ProgressManager.ProgressBar; import net.minecraftforge.fml.common.event.FMLEvent; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModDisabledEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.ThreadContext; import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; private ModContainer activeContainer; private BiMap<ModContainer, Object> modObjectList; private ListMultimap<String, ModContainer> packageOwners; public LoadController(Loader loader) { this.loader = loader; this.masterChannel = new EventBus("FMLMainChannel"); this.masterChannel.register(this); state = LoaderState.NOINIT; packageOwners = ArrayListMultimap.create(); } void disableMod(ModContainer mod) { HashMap<String, EventBus> temporary = Maps.newHashMap(eventChannels); String modId = mod.getModId(); EventBus bus = temporary.remove(modId); bus.post(new FMLModDisabledEvent()); if (errors.get(modId).isEmpty()) { eventChannels = ImmutableMap.copyOf(temporary); modStates.put(modId, ModState.DISABLED); modObjectList.remove(mod); activeModList.remove(mod); } } @Subscribe
public void buildModList(FMLLoadEvent event)
MinecraftForge/FML
src/main/java/net/minecraftforge/fml/common/LoadController.java
// Path: src/main/java/net/minecraftforge/fml/common/ProgressManager.java // @Deprecated // public static class ProgressBar // { // private final String title; // private final int steps; // private volatile int step = 0; // private volatile String message = ""; // // private ProgressBar(String title, int steps) // { // this.title = title; // this.steps = steps; // } // // public void step(Class<?> classToName, String... extra) // { // step(ClassNameUtils.shortName(classToName)+Joiner.on(' ').join(extra)); // } // // public void step(String message) // { // if(step >= steps) throw new IllegalStateException("too much steps for ProgressBar " + title); // step++; // this.message = message; // FMLCommonHandler.instance().processWindowMessages(); // } // // public String getTitle() // { // return title; // } // // public int getSteps() // { // return steps; // } // // public int getStep() // { // return step; // } // // public String getMessage() // { // return message; // } // } // // Path: src/main/java/net/minecraftforge/fml/common/event/FMLLoadEvent.java // public class FMLLoadEvent // { // // }
import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import net.minecraftforge.fml.common.LoaderState.ModState; import net.minecraftforge.fml.common.ProgressManager.ProgressBar; import net.minecraftforge.fml.common.event.FMLEvent; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModDisabledEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.ThreadContext; import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe;
} if (toThrow != null && toThrow instanceof RuntimeException) { throw (RuntimeException)toThrow; } else { throw new LoaderException(toThrow); } } else if (state != desiredState && forceState) { FMLLog.info("The state engine was in incorrect state %s and forced into state %s. Errors may have been discarded.", state, desiredState); forceState(desiredState); } } public ModContainer activeContainer() { return activeContainer != null ? activeContainer : findActiveContainerFromStack(); } @Subscribe public void propogateStateMessage(FMLEvent stateEvent) { if (stateEvent instanceof FMLPreInitializationEvent) { modObjectList = buildModObjectList(); }
// Path: src/main/java/net/minecraftforge/fml/common/ProgressManager.java // @Deprecated // public static class ProgressBar // { // private final String title; // private final int steps; // private volatile int step = 0; // private volatile String message = ""; // // private ProgressBar(String title, int steps) // { // this.title = title; // this.steps = steps; // } // // public void step(Class<?> classToName, String... extra) // { // step(ClassNameUtils.shortName(classToName)+Joiner.on(' ').join(extra)); // } // // public void step(String message) // { // if(step >= steps) throw new IllegalStateException("too much steps for ProgressBar " + title); // step++; // this.message = message; // FMLCommonHandler.instance().processWindowMessages(); // } // // public String getTitle() // { // return title; // } // // public int getSteps() // { // return steps; // } // // public int getStep() // { // return step; // } // // public String getMessage() // { // return message; // } // } // // Path: src/main/java/net/minecraftforge/fml/common/event/FMLLoadEvent.java // public class FMLLoadEvent // { // // } // Path: src/main/java/net/minecraftforge/fml/common/LoadController.java import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import net.minecraftforge.fml.common.LoaderState.ModState; import net.minecraftforge.fml.common.ProgressManager.ProgressBar; import net.minecraftforge.fml.common.event.FMLEvent; import net.minecraftforge.fml.common.event.FMLLoadEvent; import net.minecraftforge.fml.common.event.FMLModDisabledEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction; import net.minecraftforge.fml.common.versioning.ArtifactVersion; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.ThreadContext; import com.google.common.base.Joiner; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; } if (toThrow != null && toThrow instanceof RuntimeException) { throw (RuntimeException)toThrow; } else { throw new LoaderException(toThrow); } } else if (state != desiredState && forceState) { FMLLog.info("The state engine was in incorrect state %s and forced into state %s. Errors may have been discarded.", state, desiredState); forceState(desiredState); } } public ModContainer activeContainer() { return activeContainer != null ? activeContainer : findActiveContainerFromStack(); } @Subscribe public void propogateStateMessage(FMLEvent stateEvent) { if (stateEvent instanceof FMLPreInitializationEvent) { modObjectList = buildModObjectList(); }
ProgressBar bar = ProgressManager.push(stateEvent.description(), activeModList.size());
MinecraftForge/FML
src/main/java/net/minecraftforge/fml/common/LoaderState.java
// Path: src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java // public class FMLServerStartedEvent extends FMLStateEvent // { // // public FMLServerStartedEvent(Object... data) // { // super(data); // } // // @Override // public ModState getModState() // { // return ModState.AVAILABLE; // } // // }
import net.minecraftforge.fml.common.event.FMLConstructionEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent; import net.minecraftforge.fml.common.event.FMLServerStartedEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLServerStoppedEvent; import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import com.google.common.base.Throwables;
/* * Forge Mod Loader * Copyright (c) 2012-2013 cpw. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * cpw - implementation */ package net.minecraftforge.fml.common; /** * The state enum used to help track state progression for the loader * @author cpw * */ public enum LoaderState { NOINIT("Uninitialized",null), LOADING("Loading",null), CONSTRUCTING("Constructing mods",FMLConstructionEvent.class), PREINITIALIZATION("Pre-initializing mods", FMLPreInitializationEvent.class), INITIALIZATION("Initializing mods", FMLInitializationEvent.class), POSTINITIALIZATION("Post-initializing mods", FMLPostInitializationEvent.class), AVAILABLE("Mod loading complete", FMLLoadCompleteEvent.class), SERVER_ABOUT_TO_START("Server about to start", FMLServerAboutToStartEvent.class), SERVER_STARTING("Server starting", FMLServerStartingEvent.class),
// Path: src/main/java/net/minecraftforge/fml/common/event/FMLServerStartedEvent.java // public class FMLServerStartedEvent extends FMLStateEvent // { // // public FMLServerStartedEvent(Object... data) // { // super(data); // } // // @Override // public ModState getModState() // { // return ModState.AVAILABLE; // } // // } // Path: src/main/java/net/minecraftforge/fml/common/LoaderState.java import net.minecraftforge.fml.common.event.FMLConstructionEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerAboutToStartEvent; import net.minecraftforge.fml.common.event.FMLServerStartedEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.event.FMLServerStoppedEvent; import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; import net.minecraftforge.fml.common.event.FMLStateEvent; import com.google.common.base.Throwables; /* * Forge Mod Loader * Copyright (c) 2012-2013 cpw. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * cpw - implementation */ package net.minecraftforge.fml.common; /** * The state enum used to help track state progression for the loader * @author cpw * */ public enum LoaderState { NOINIT("Uninitialized",null), LOADING("Loading",null), CONSTRUCTING("Constructing mods",FMLConstructionEvent.class), PREINITIALIZATION("Pre-initializing mods", FMLPreInitializationEvent.class), INITIALIZATION("Initializing mods", FMLInitializationEvent.class), POSTINITIALIZATION("Post-initializing mods", FMLPostInitializationEvent.class), AVAILABLE("Mod loading complete", FMLLoadCompleteEvent.class), SERVER_ABOUT_TO_START("Server about to start", FMLServerAboutToStartEvent.class), SERVER_STARTING("Server starting", FMLServerStartingEvent.class),
SERVER_STARTED("Server started", FMLServerStartedEvent.class),
osiam/auth-server
src/main/java/org/osiam/security/helper/LoginDecisionFilter.java
// Path: src/main/java/org/osiam/auth/login/internal/InternalAuthentication.java // public class InternalAuthentication extends UsernamePasswordAuthenticationToken { // // private static final long serialVersionUID = 5020697919339414782L; // // public InternalAuthentication(Object principal, Object credentials) { // super(principal, credentials); // } // // public InternalAuthentication(Object principal, Object credentials, // Collection<? extends GrantedAuthority> authorities) { // super(principal, credentials, authorities); // } // }
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.common.base.Strings; import org.osiam.auth.login.internal.InternalAuthentication; import org.osiam.auth.login.ldap.OsiamLdapAuthentication; import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.helper; public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { public static final String USERNAME_PARAMETER = "username"; private static final String PASSWORD_PARAMETER = "password"; private boolean postOnly = true; public LoginDecisionFilter() { super("/login/check"); } @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } String username = request.getParameter(getUsernameParameter()); String password = request.getParameter(getPasswordParameter()); if (username == null) { username = ""; } if (password == null) { password = ""; } username = username.trim(); String provider = request.getParameter("provider"); UsernamePasswordAuthenticationToken authRequest; if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { authRequest = new OsiamLdapAuthentication(username, password); } else {
// Path: src/main/java/org/osiam/auth/login/internal/InternalAuthentication.java // public class InternalAuthentication extends UsernamePasswordAuthenticationToken { // // private static final long serialVersionUID = 5020697919339414782L; // // public InternalAuthentication(Object principal, Object credentials) { // super(principal, credentials); // } // // public InternalAuthentication(Object principal, Object credentials, // Collection<? extends GrantedAuthority> authorities) { // super(principal, credentials, authorities); // } // } // Path: src/main/java/org/osiam/security/helper/LoginDecisionFilter.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.common.base.Strings; import org.osiam.auth.login.internal.InternalAuthentication; import org.osiam.auth.login.ldap.OsiamLdapAuthentication; import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.helper; public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { public static final String USERNAME_PARAMETER = "username"; private static final String PASSWORD_PARAMETER = "password"; private boolean postOnly = true; public LoginDecisionFilter() { super("/login/check"); } @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } String username = request.getParameter(getUsernameParameter()); String password = request.getParameter(getPasswordParameter()); if (username == null) { username = ""; } if (password == null) { password = ""; } username = username.trim(); String provider = request.getParameter("provider"); UsernamePasswordAuthenticationToken authRequest; if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { authRequest = new OsiamLdapAuthentication(username, password); } else {
authRequest = new InternalAuthentication(username, password);
osiam/auth-server
src/main/java/org/osiam/auth/configuration/OAuth2ResourceServerConfig.java
// Path: src/main/java/org/osiam/security/authorization/OsiamMethodSecurityExpressionHandler.java // public class OsiamMethodSecurityExpressionHandler extends OAuth2WebSecurityExpressionHandler { // // public OsiamMethodSecurityExpressionHandler() { // super(); // this.setExpressionParser(new OsiamDelegateExpressionParser(this.getExpressionParser())); // } // // public StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, // FilterInvocation filterInvocation) { // StandardEvaluationContext ec = super.createEvaluationContextInternal(authentication, filterInvocation); // ec.setVariable("osiam", new OsiamSecurityExpressionMethods(authentication, filterInvocation)); // return ec; // } // }
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler; import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint; import org.springframework.security.oauth2.provider.token.DefaultTokenServices; import org.osiam.security.authorization.OsiamMethodSecurityExpressionHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.configuration; @Configuration @EnableResourceServer public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter { @Autowired private DefaultTokenServices tokenService; @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { resources.resourceId("oauth2res") .tokenServices(tokenService)
// Path: src/main/java/org/osiam/security/authorization/OsiamMethodSecurityExpressionHandler.java // public class OsiamMethodSecurityExpressionHandler extends OAuth2WebSecurityExpressionHandler { // // public OsiamMethodSecurityExpressionHandler() { // super(); // this.setExpressionParser(new OsiamDelegateExpressionParser(this.getExpressionParser())); // } // // public StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, // FilterInvocation filterInvocation) { // StandardEvaluationContext ec = super.createEvaluationContextInternal(authentication, filterInvocation); // ec.setVariable("osiam", new OsiamSecurityExpressionMethods(authentication, filterInvocation)); // return ec; // } // } // Path: src/main/java/org/osiam/auth/configuration/OAuth2ResourceServerConfig.java import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler; import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint; import org.springframework.security.oauth2.provider.token.DefaultTokenServices; import org.osiam.security.authorization.OsiamMethodSecurityExpressionHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.configuration; @Configuration @EnableResourceServer public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter { @Autowired private DefaultTokenServices tokenService; @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { resources.resourceId("oauth2res") .tokenServices(tokenService)
.expressionHandler(new OsiamMethodSecurityExpressionHandler())
osiam/auth-server
src/main/java/org/osiam/auth/login/ldap/ScimToLdapAttributeMapping.java
// Path: src/main/java/org/osiam/auth/exception/LdapConfigurationException.java // public class LdapConfigurationException extends AuthenticationException { // // public LdapConfigurationException(String s) { // super(s); // } // // public LdapConfigurationException(String s, Throwable cause) { // super(s, cause); // } // }
import java.util.Map; import org.osiam.auth.exception.LdapConfigurationException; import org.osiam.resources.scim.User; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DirContextOperations; import java.util.Collection; import java.util.HashMap;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login.ldap; public class ScimToLdapAttributeMapping { private final Map<String, String> scimToLdapAttributes = new HashMap<>(); public ScimToLdapAttributeMapping(final String[] attributeMapping) { for (String keyValuePair : attributeMapping) { if (!keyValuePair.contains(":")) {
// Path: src/main/java/org/osiam/auth/exception/LdapConfigurationException.java // public class LdapConfigurationException extends AuthenticationException { // // public LdapConfigurationException(String s) { // super(s); // } // // public LdapConfigurationException(String s, Throwable cause) { // super(s, cause); // } // } // Path: src/main/java/org/osiam/auth/login/ldap/ScimToLdapAttributeMapping.java import java.util.Map; import org.osiam.auth.exception.LdapConfigurationException; import org.osiam.resources.scim.User; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DirContextOperations; import java.util.Collection; import java.util.HashMap; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login.ldap; public class ScimToLdapAttributeMapping { private final Map<String, String> scimToLdapAttributes = new HashMap<>(); public ScimToLdapAttributeMapping(final String[] attributeMapping) { for (String keyValuePair : attributeMapping) { if (!keyValuePair.contains(":")) {
throw new LdapConfigurationException("The ldap attribute mapping value '" + keyValuePair
osiam/auth-server
src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // }
import org.springframework.security.oauth2.provider.OAuth2Request; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.client.oauth.AccessToken; import org.osiam.client.oauth.Scope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.provider.OAuth2Authentication;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.token; /** * TokenProvider which created an accesstoken for the auth server client */ @Service public class OsiamAccessTokenProvider { @Autowired private TokenStore tokenStore; public AccessToken createAccessToken() { Set<String> scopes = new HashSet<>(); scopes.add(Scope.ADMIN.toString()); // Random scope, because the token services generates for every scope but same client // a different access token. This is only made due to the token expired problem, when the auth server // takes his actual access token, but the token is expired during the request to the resource server scopes.add(new Scope(UUID.randomUUID().toString()).toString()); Map<String, String> parameters = new HashMap<>();
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // } // Path: src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java import org.springframework.security.oauth2.provider.OAuth2Request; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.client.oauth.AccessToken; import org.osiam.client.oauth.Scope; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.security.oauth2.provider.OAuth2Authentication; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.token; /** * TokenProvider which created an accesstoken for the auth server client */ @Service public class OsiamAccessTokenProvider { @Autowired private TokenStore tokenStore; public AccessToken createAccessToken() { Set<String> scopes = new HashSet<>(); scopes.add(Scope.ADMIN.toString()); // Random scope, because the token services generates for every scope but same client // a different access token. This is only made due to the token expired problem, when the auth server // takes his actual access token, but the token is expired during the request to the resource server scopes.add(new Scope(UUID.randomUUID().toString()).toString()); Map<String, String> parameters = new HashMap<>();
parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID);
osiam/auth-server
src/main/java/org/osiam/auth/login/ResourceServerConnector.java
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // } // // Path: src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java // @Service // public class OsiamAccessTokenProvider { // // @Autowired // private TokenStore tokenStore; // // public AccessToken createAccessToken() { // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Random scope, because the token services generates for every scope but same client // // a different access token. This is only made due to the token expired problem, when the auth server // // takes his actual access token, but the token is expired during the request to the resource server // scopes.add(new Scope(UUID.randomUUID().toString()).toString()); // // Map<String, String> parameters = new HashMap<>(); // parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID); // OAuth2Request authRequest = new OAuth2Request( // parameters, OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID, null, true, scopes, // null, null, null, null // ); // // OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(authRequest, null); // // OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); // // tokenStore.storeAccessToken(oAuth2AccessToken, oAuth2Authentication); // // return new AccessToken.Builder(oAuth2AccessToken.getValue()).build(); // } // }
import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.auth.token.OsiamAccessTokenProvider; import org.osiam.client.OsiamConnector; import org.osiam.client.query.Query; import org.osiam.client.query.QueryBuilder; import org.osiam.resources.scim.SCIMSearchResult; import org.osiam.resources.scim.UpdateUser;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; @Service public class ResourceServerConnector implements InitializingBean{ @Value("${org.osiam.resource-server.home}") private String resourceServerHome; @Value("${org.osiam.auth-server.home}") private String authServerHome; @Value("${org.osiam.resource-server.connector.max-connections:40}") private int maxConnections; @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") private int readTimeout; @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") private int connectTimeout; @Autowired
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // } // // Path: src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java // @Service // public class OsiamAccessTokenProvider { // // @Autowired // private TokenStore tokenStore; // // public AccessToken createAccessToken() { // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Random scope, because the token services generates for every scope but same client // // a different access token. This is only made due to the token expired problem, when the auth server // // takes his actual access token, but the token is expired during the request to the resource server // scopes.add(new Scope(UUID.randomUUID().toString()).toString()); // // Map<String, String> parameters = new HashMap<>(); // parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID); // OAuth2Request authRequest = new OAuth2Request( // parameters, OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID, null, true, scopes, // null, null, null, null // ); // // OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(authRequest, null); // // OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); // // tokenStore.storeAccessToken(oAuth2AccessToken, oAuth2Authentication); // // return new AccessToken.Builder(oAuth2AccessToken.getValue()).build(); // } // } // Path: src/main/java/org/osiam/auth/login/ResourceServerConnector.java import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.auth.token.OsiamAccessTokenProvider; import org.osiam.client.OsiamConnector; import org.osiam.client.query.Query; import org.osiam.client.query.QueryBuilder; import org.osiam.resources.scim.SCIMSearchResult; import org.osiam.resources.scim.UpdateUser; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; @Service public class ResourceServerConnector implements InitializingBean{ @Value("${org.osiam.resource-server.home}") private String resourceServerHome; @Value("${org.osiam.auth-server.home}") private String authServerHome; @Value("${org.osiam.resource-server.connector.max-connections:40}") private int maxConnections; @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") private int readTimeout; @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") private int connectTimeout; @Autowired
private OsiamAccessTokenProvider osiamAccessTokenProvider;
osiam/auth-server
src/main/java/org/osiam/auth/login/ResourceServerConnector.java
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // } // // Path: src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java // @Service // public class OsiamAccessTokenProvider { // // @Autowired // private TokenStore tokenStore; // // public AccessToken createAccessToken() { // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Random scope, because the token services generates for every scope but same client // // a different access token. This is only made due to the token expired problem, when the auth server // // takes his actual access token, but the token is expired during the request to the resource server // scopes.add(new Scope(UUID.randomUUID().toString()).toString()); // // Map<String, String> parameters = new HashMap<>(); // parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID); // OAuth2Request authRequest = new OAuth2Request( // parameters, OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID, null, true, scopes, // null, null, null, null // ); // // OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(authRequest, null); // // OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); // // tokenStore.storeAccessToken(oAuth2AccessToken, oAuth2Authentication); // // return new AccessToken.Builder(oAuth2AccessToken.getValue()).build(); // } // }
import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.auth.token.OsiamAccessTokenProvider; import org.osiam.client.OsiamConnector; import org.osiam.client.query.Query; import org.osiam.client.query.QueryBuilder; import org.osiam.resources.scim.SCIMSearchResult; import org.osiam.resources.scim.UpdateUser;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; @Service public class ResourceServerConnector implements InitializingBean{ @Value("${org.osiam.resource-server.home}") private String resourceServerHome; @Value("${org.osiam.auth-server.home}") private String authServerHome; @Value("${org.osiam.resource-server.connector.max-connections:40}") private int maxConnections; @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") private int readTimeout; @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") private int connectTimeout; @Autowired private OsiamAccessTokenProvider osiamAccessTokenProvider; @Autowired
// Path: src/main/java/org/osiam/auth/oauth_client/OsiamAuthServerClientProvider.java // @Service // public class OsiamAuthServerClientProvider { // // private static final Logger LOGGER = LoggerFactory.getLogger(OsiamAuthServerClientProvider.class.getName()); // // public static final String AUTH_SERVER_CLIENT_ID = "auth-server"; // public static final int CLIENT_VALIDITY = 10; // // @Autowired // private PlatformTransactionManager txManager; // // @Autowired // private ClientRepository clientRepository; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // private String authServerClientSecret; // // @PostConstruct // private void createAuthServerClient() { // TransactionTemplate transactionTemplate = new TransactionTemplate(txManager); // transactionTemplate.execute(new TransactionCallbackWithoutResult() { // @Override // protected void doInTransactionWithoutResult(TransactionStatus status) { // if (!clientRepository.existsById(AUTH_SERVER_CLIENT_ID)) { // LOGGER.info("No auth server client found, so it will be created."); // int validity = CLIENT_VALIDITY; // // ClientEntity clientEntity = new ClientEntity(); // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Set<String> grants = new HashSet<>(); // grants.add(GrantType.CLIENT_CREDENTIALS.toString()); // // clientEntity.setClientId(AUTH_SERVER_CLIENT_ID); // clientEntity.setRefreshTokenValiditySeconds(validity); // clientEntity.setAccessTokenValiditySeconds(validity); // clientEntity.setRedirectUri(authServerHome); // clientEntity.setScope(scopes); // clientEntity.setImplicit(true); // clientEntity.setValidityInSeconds(validity); // clientEntity.setGrants(grants); // // clientEntity = clientRepository.save(clientEntity); // authServerClientSecret = clientEntity.getClientSecret(); // } // } // }); // } // // public String getClientSecret() { // return authServerClientSecret; // } // } // // Path: src/main/java/org/osiam/auth/token/OsiamAccessTokenProvider.java // @Service // public class OsiamAccessTokenProvider { // // @Autowired // private TokenStore tokenStore; // // public AccessToken createAccessToken() { // Set<String> scopes = new HashSet<>(); // scopes.add(Scope.ADMIN.toString()); // // Random scope, because the token services generates for every scope but same client // // a different access token. This is only made due to the token expired problem, when the auth server // // takes his actual access token, but the token is expired during the request to the resource server // scopes.add(new Scope(UUID.randomUUID().toString()).toString()); // // Map<String, String> parameters = new HashMap<>(); // parameters.put("client_id", OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID); // OAuth2Request authRequest = new OAuth2Request( // parameters, OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID, null, true, scopes, // null, null, null, null // ); // // OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(authRequest, null); // // OAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(UUID.randomUUID().toString()); // // tokenStore.storeAccessToken(oAuth2AccessToken, oAuth2Authentication); // // return new AccessToken.Builder(oAuth2AccessToken.getValue()).build(); // } // } // Path: src/main/java/org/osiam/auth/login/ResourceServerConnector.java import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.osiam.auth.oauth_client.OsiamAuthServerClientProvider; import org.osiam.auth.token.OsiamAccessTokenProvider; import org.osiam.client.OsiamConnector; import org.osiam.client.query.Query; import org.osiam.client.query.QueryBuilder; import org.osiam.resources.scim.SCIMSearchResult; import org.osiam.resources.scim.UpdateUser; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; @Service public class ResourceServerConnector implements InitializingBean{ @Value("${org.osiam.resource-server.home}") private String resourceServerHome; @Value("${org.osiam.auth-server.home}") private String authServerHome; @Value("${org.osiam.resource-server.connector.max-connections:40}") private int maxConnections; @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") private int readTimeout; @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") private int connectTimeout; @Autowired private OsiamAccessTokenProvider osiamAccessTokenProvider; @Autowired
private OsiamAuthServerClientProvider authServerClientProvider;
osiam/auth-server
src/main/java/org/osiam/auth/login/OsiamCachingAuthenticationFailureHandler.java
// Path: src/main/java/org/osiam/auth/exception/LdapAuthenticationProcessException.java // public class LdapAuthenticationProcessException extends AuthenticationException { // // public LdapAuthenticationProcessException(String s) { // super(s); // } // } // // Path: src/main/java/org/osiam/security/helper/LoginDecisionFilter.java // public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { // // public static final String USERNAME_PARAMETER = "username"; // private static final String PASSWORD_PARAMETER = "password"; // // private boolean postOnly = true; // // public LoginDecisionFilter() { // super("/login/check"); // } // // @Override // public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { // if (postOnly && !request.getMethod().equals("POST")) { // throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); // } // // String username = request.getParameter(getUsernameParameter()); // String password = request.getParameter(getPasswordParameter()); // // if (username == null) { // username = ""; // } // // if (password == null) { // password = ""; // } // // username = username.trim(); // // String provider = request.getParameter("provider"); // // UsernamePasswordAuthenticationToken authRequest; // if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { // authRequest = new OsiamLdapAuthentication(username, password); // } else { // authRequest = new InternalAuthentication(username, password); // } // // setDetails(request, authRequest); // return this.getAuthenticationManager().authenticate(authRequest); // } // // /** // * Provided so that subclasses may configure what is put into the authentication request's details property. // * // * @param request // * that an authentication request is being created for // * @param authRequest // * the authentication request object that should have its details set // */ // protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) { // authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); // } // // /** // * Defines whether only HTTP POST requests will be allowed by this filter. If set to true, and an authentication // * request is received which is not a POST request, an exception will be raised immediately and authentication will // * not be attempted. The <tt>unsuccessfulAuthentication()</tt> method will be called as if handling a failed // * authentication. // * <p> // * Defaults to <tt>true</tt> but may be overridden by subclasses. // */ // public void setPostOnly(boolean postOnly) { // this.postOnly = postOnly; // } // // public final String getUsernameParameter() { // return USERNAME_PARAMETER; // } // // public final String getPasswordParameter() { // return PASSWORD_PARAMETER; // } // }
import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import com.google.common.base.Strings; import org.osiam.auth.exception.LdapAuthenticationProcessException; import org.osiam.security.helper.LoginDecisionFilter; import org.springframework.security.authentication.LockedException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; public class OsiamCachingAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { private static final String LAST_USERNAME_KEY = "LAST_USERNAME"; private static final String LAST_PROVIDER_KEY = "LAST_PROVIDER"; private static final String ERROR_KEY = "ERROR_KEY"; private static final String IS_LOCKED = "IS_LOCKED"; public OsiamCachingAuthenticationFailureHandler(String defaultFailureUrl) { super(defaultFailureUrl); } @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { super.onAuthenticationFailure(request, response, exception); if (request.getSession(false) == null && !isAllowSessionCreation()) { return; } request.getSession().setAttribute(
// Path: src/main/java/org/osiam/auth/exception/LdapAuthenticationProcessException.java // public class LdapAuthenticationProcessException extends AuthenticationException { // // public LdapAuthenticationProcessException(String s) { // super(s); // } // } // // Path: src/main/java/org/osiam/security/helper/LoginDecisionFilter.java // public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { // // public static final String USERNAME_PARAMETER = "username"; // private static final String PASSWORD_PARAMETER = "password"; // // private boolean postOnly = true; // // public LoginDecisionFilter() { // super("/login/check"); // } // // @Override // public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { // if (postOnly && !request.getMethod().equals("POST")) { // throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); // } // // String username = request.getParameter(getUsernameParameter()); // String password = request.getParameter(getPasswordParameter()); // // if (username == null) { // username = ""; // } // // if (password == null) { // password = ""; // } // // username = username.trim(); // // String provider = request.getParameter("provider"); // // UsernamePasswordAuthenticationToken authRequest; // if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { // authRequest = new OsiamLdapAuthentication(username, password); // } else { // authRequest = new InternalAuthentication(username, password); // } // // setDetails(request, authRequest); // return this.getAuthenticationManager().authenticate(authRequest); // } // // /** // * Provided so that subclasses may configure what is put into the authentication request's details property. // * // * @param request // * that an authentication request is being created for // * @param authRequest // * the authentication request object that should have its details set // */ // protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) { // authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); // } // // /** // * Defines whether only HTTP POST requests will be allowed by this filter. If set to true, and an authentication // * request is received which is not a POST request, an exception will be raised immediately and authentication will // * not be attempted. The <tt>unsuccessfulAuthentication()</tt> method will be called as if handling a failed // * authentication. // * <p> // * Defaults to <tt>true</tt> but may be overridden by subclasses. // */ // public void setPostOnly(boolean postOnly) { // this.postOnly = postOnly; // } // // public final String getUsernameParameter() { // return USERNAME_PARAMETER; // } // // public final String getPasswordParameter() { // return PASSWORD_PARAMETER; // } // } // Path: src/main/java/org/osiam/auth/login/OsiamCachingAuthenticationFailureHandler.java import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import com.google.common.base.Strings; import org.osiam.auth.exception.LdapAuthenticationProcessException; import org.osiam.security.helper.LoginDecisionFilter; import org.springframework.security.authentication.LockedException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; public class OsiamCachingAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { private static final String LAST_USERNAME_KEY = "LAST_USERNAME"; private static final String LAST_PROVIDER_KEY = "LAST_PROVIDER"; private static final String ERROR_KEY = "ERROR_KEY"; private static final String IS_LOCKED = "IS_LOCKED"; public OsiamCachingAuthenticationFailureHandler(String defaultFailureUrl) { super(defaultFailureUrl); } @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { super.onAuthenticationFailure(request, response, exception); if (request.getSession(false) == null && !isAllowSessionCreation()) { return; } request.getSession().setAttribute(
LAST_USERNAME_KEY, request.getParameter(LoginDecisionFilter.USERNAME_PARAMETER)
osiam/auth-server
src/main/java/org/osiam/auth/login/OsiamCachingAuthenticationFailureHandler.java
// Path: src/main/java/org/osiam/auth/exception/LdapAuthenticationProcessException.java // public class LdapAuthenticationProcessException extends AuthenticationException { // // public LdapAuthenticationProcessException(String s) { // super(s); // } // } // // Path: src/main/java/org/osiam/security/helper/LoginDecisionFilter.java // public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { // // public static final String USERNAME_PARAMETER = "username"; // private static final String PASSWORD_PARAMETER = "password"; // // private boolean postOnly = true; // // public LoginDecisionFilter() { // super("/login/check"); // } // // @Override // public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { // if (postOnly && !request.getMethod().equals("POST")) { // throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); // } // // String username = request.getParameter(getUsernameParameter()); // String password = request.getParameter(getPasswordParameter()); // // if (username == null) { // username = ""; // } // // if (password == null) { // password = ""; // } // // username = username.trim(); // // String provider = request.getParameter("provider"); // // UsernamePasswordAuthenticationToken authRequest; // if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { // authRequest = new OsiamLdapAuthentication(username, password); // } else { // authRequest = new InternalAuthentication(username, password); // } // // setDetails(request, authRequest); // return this.getAuthenticationManager().authenticate(authRequest); // } // // /** // * Provided so that subclasses may configure what is put into the authentication request's details property. // * // * @param request // * that an authentication request is being created for // * @param authRequest // * the authentication request object that should have its details set // */ // protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) { // authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); // } // // /** // * Defines whether only HTTP POST requests will be allowed by this filter. If set to true, and an authentication // * request is received which is not a POST request, an exception will be raised immediately and authentication will // * not be attempted. The <tt>unsuccessfulAuthentication()</tt> method will be called as if handling a failed // * authentication. // * <p> // * Defaults to <tt>true</tt> but may be overridden by subclasses. // */ // public void setPostOnly(boolean postOnly) { // this.postOnly = postOnly; // } // // public final String getUsernameParameter() { // return USERNAME_PARAMETER; // } // // public final String getPasswordParameter() { // return PASSWORD_PARAMETER; // } // }
import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import com.google.common.base.Strings; import org.osiam.auth.exception.LdapAuthenticationProcessException; import org.osiam.security.helper.LoginDecisionFilter; import org.springframework.security.authentication.LockedException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; public class OsiamCachingAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { private static final String LAST_USERNAME_KEY = "LAST_USERNAME"; private static final String LAST_PROVIDER_KEY = "LAST_PROVIDER"; private static final String ERROR_KEY = "ERROR_KEY"; private static final String IS_LOCKED = "IS_LOCKED"; public OsiamCachingAuthenticationFailureHandler(String defaultFailureUrl) { super(defaultFailureUrl); } @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { super.onAuthenticationFailure(request, response, exception); if (request.getSession(false) == null && !isAllowSessionCreation()) { return; } request.getSession().setAttribute( LAST_USERNAME_KEY, request.getParameter(LoginDecisionFilter.USERNAME_PARAMETER) ); request.getSession().setAttribute( LAST_PROVIDER_KEY, Strings.isNullOrEmpty(request.getParameter("provider")) ? "internal" : request.getParameter("provider") ); request.getSession().setAttribute(IS_LOCKED, false);
// Path: src/main/java/org/osiam/auth/exception/LdapAuthenticationProcessException.java // public class LdapAuthenticationProcessException extends AuthenticationException { // // public LdapAuthenticationProcessException(String s) { // super(s); // } // } // // Path: src/main/java/org/osiam/security/helper/LoginDecisionFilter.java // public class LoginDecisionFilter extends AbstractAuthenticationProcessingFilter { // // public static final String USERNAME_PARAMETER = "username"; // private static final String PASSWORD_PARAMETER = "password"; // // private boolean postOnly = true; // // public LoginDecisionFilter() { // super("/login/check"); // } // // @Override // public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) { // if (postOnly && !request.getMethod().equals("POST")) { // throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); // } // // String username = request.getParameter(getUsernameParameter()); // String password = request.getParameter(getPasswordParameter()); // // if (username == null) { // username = ""; // } // // if (password == null) { // password = ""; // } // // username = username.trim(); // // String provider = request.getParameter("provider"); // // UsernamePasswordAuthenticationToken authRequest; // if (!Strings.isNullOrEmpty(provider) && provider.equals("ldap")) { // authRequest = new OsiamLdapAuthentication(username, password); // } else { // authRequest = new InternalAuthentication(username, password); // } // // setDetails(request, authRequest); // return this.getAuthenticationManager().authenticate(authRequest); // } // // /** // * Provided so that subclasses may configure what is put into the authentication request's details property. // * // * @param request // * that an authentication request is being created for // * @param authRequest // * the authentication request object that should have its details set // */ // protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) { // authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); // } // // /** // * Defines whether only HTTP POST requests will be allowed by this filter. If set to true, and an authentication // * request is received which is not a POST request, an exception will be raised immediately and authentication will // * not be attempted. The <tt>unsuccessfulAuthentication()</tt> method will be called as if handling a failed // * authentication. // * <p> // * Defaults to <tt>true</tt> but may be overridden by subclasses. // */ // public void setPostOnly(boolean postOnly) { // this.postOnly = postOnly; // } // // public final String getUsernameParameter() { // return USERNAME_PARAMETER; // } // // public final String getPasswordParameter() { // return PASSWORD_PARAMETER; // } // } // Path: src/main/java/org/osiam/auth/login/OsiamCachingAuthenticationFailureHandler.java import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import com.google.common.base.Strings; import org.osiam.auth.exception.LdapAuthenticationProcessException; import org.osiam.security.helper.LoginDecisionFilter; import org.springframework.security.authentication.LockedException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login; public class OsiamCachingAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { private static final String LAST_USERNAME_KEY = "LAST_USERNAME"; private static final String LAST_PROVIDER_KEY = "LAST_PROVIDER"; private static final String ERROR_KEY = "ERROR_KEY"; private static final String IS_LOCKED = "IS_LOCKED"; public OsiamCachingAuthenticationFailureHandler(String defaultFailureUrl) { super(defaultFailureUrl); } @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { super.onAuthenticationFailure(request, response, exception); if (request.getSession(false) == null && !isAllowSessionCreation()) { return; } request.getSession().setAttribute( LAST_USERNAME_KEY, request.getParameter(LoginDecisionFilter.USERNAME_PARAMETER) ); request.getSession().setAttribute( LAST_PROVIDER_KEY, Strings.isNullOrEmpty(request.getParameter("provider")) ? "internal" : request.getParameter("provider") ); request.getSession().setAttribute(IS_LOCKED, false);
if (exception instanceof LdapAuthenticationProcessException) {
osiam/auth-server
src/main/java/org/osiam/security/authorization/OsiamUserApprovalHandler.java
// Path: src/main/java/org/osiam/security/authentication/OsiamClientDetailsService.java // @Service // public class OsiamClientDetailsService implements ClientDetailsService { // // @Autowired // private ClientRepository clientRepository; // // @Override // public ClientDetails loadClientByClientId(final String clientId) { // return clientRepository.findById(clientId); // } // }
import javax.servlet.http.HttpSession; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import org.osiam.security.authentication.OsiamClientDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.provider.AuthorizationRequest; import org.springframework.security.oauth2.provider.ClientDetails; import org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler; import org.springframework.stereotype.Component;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.authorization; /** * A default user approval handler that doesn't remember any decisions. * * @author Dave Syer */ @Component public class OsiamUserApprovalHandler extends DefaultUserApprovalHandler { private static final String APPROVALS_SESSION_KEY = "osiam_oauth_approvals"; private static final String IS_PRE_APPROVED_PARAMETER = "osiam_is_pre_approved"; @Autowired private HttpSession httpSession; @Autowired
// Path: src/main/java/org/osiam/security/authentication/OsiamClientDetailsService.java // @Service // public class OsiamClientDetailsService implements ClientDetailsService { // // @Autowired // private ClientRepository clientRepository; // // @Override // public ClientDetails loadClientByClientId(final String clientId) { // return clientRepository.findById(clientId); // } // } // Path: src/main/java/org/osiam/security/authorization/OsiamUserApprovalHandler.java import javax.servlet.http.HttpSession; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import org.osiam.security.authentication.OsiamClientDetailsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.provider.AuthorizationRequest; import org.springframework.security.oauth2.provider.ClientDetails; import org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler; import org.springframework.stereotype.Component; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.authorization; /** * A default user approval handler that doesn't remember any decisions. * * @author Dave Syer */ @Component public class OsiamUserApprovalHandler extends DefaultUserApprovalHandler { private static final String APPROVALS_SESSION_KEY = "osiam_oauth_approvals"; private static final String IS_PRE_APPROVED_PARAMETER = "osiam_is_pre_approved"; @Autowired private HttpSession httpSession; @Autowired
private OsiamClientDetailsService osiamClientDetailsService;
osiam/auth-server
src/main/java/org/osiam/security/authentication/OsiamClientDetailsService.java
// Path: src/main/java/org/osiam/auth/oauth_client/ClientRepository.java // @Transactional // @Repository // public interface ClientRepository extends JpaRepository<ClientEntity, Long> { // // ClientEntity findById(String id); // // void deleteById(String id); // // @Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM ClientEntity c WHERE c.id = :id") // boolean existsById(@Param("id") String id); // // @Query("select c.id from ClientEntity c") // List<String> findAllClientIds(); // }
import org.osiam.auth.oauth_client.ClientRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.provider.ClientDetails; import org.springframework.security.oauth2.provider.ClientDetailsService; import org.springframework.stereotype.Service;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.authentication; /** * OSIAM {@link ClientDetailsService} implementation. */ @Service public class OsiamClientDetailsService implements ClientDetailsService { @Autowired
// Path: src/main/java/org/osiam/auth/oauth_client/ClientRepository.java // @Transactional // @Repository // public interface ClientRepository extends JpaRepository<ClientEntity, Long> { // // ClientEntity findById(String id); // // void deleteById(String id); // // @Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM ClientEntity c WHERE c.id = :id") // boolean existsById(@Param("id") String id); // // @Query("select c.id from ClientEntity c") // List<String> findAllClientIds(); // } // Path: src/main/java/org/osiam/security/authentication/OsiamClientDetailsService.java import org.osiam.auth.oauth_client.ClientRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.provider.ClientDetails; import org.springframework.security.oauth2.provider.ClientDetailsService; import org.springframework.stereotype.Service; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.security.authentication; /** * OSIAM {@link ClientDetailsService} implementation. */ @Service public class OsiamClientDetailsService implements ClientDetailsService { @Autowired
private ClientRepository clientRepository;
osiam/auth-server
src/main/java/org/osiam/auth/login/internal/InternalAuthenticationProvider.java
// Path: src/main/java/org/osiam/auth/login/ResourceServerConnector.java // @Service // public class ResourceServerConnector implements InitializingBean{ // // @Value("${org.osiam.resource-server.home}") // private String resourceServerHome; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // @Value("${org.osiam.resource-server.connector.max-connections:40}") // private int maxConnections; // // @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") // private int readTimeout; // // @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") // private int connectTimeout; // // @Autowired // private OsiamAccessTokenProvider osiamAccessTokenProvider; // // @Autowired // private OsiamAuthServerClientProvider authServerClientProvider; // // @Override // public void afterPropertiesSet() throws Exception { // OsiamConnector.setMaxConnections(maxConnections); // OsiamConnector.setMaxConnectionsPerRoute(maxConnections); // } // // public User getUserByUsername(final String userName) { // Query query = new QueryBuilder().filter("userName eq \"" + userName + "\"").build(); // // SCIMSearchResult<User> result = createOsiamConnector().searchUsers(query, // osiamAccessTokenProvider.createAccessToken()); // // if (result.getTotalResults() != 1) { // return null; // } else { // return result.getResources().get(0); // } // } // // public User getUserById(final String id) { // return createOsiamConnector().getUser(id, osiamAccessTokenProvider.createAccessToken()); // } // // public User createUser(User user) { // return createOsiamConnector().createUser(user, osiamAccessTokenProvider.createAccessToken()); // } // // public User updateUser(String userId, UpdateUser user) { // return createOsiamConnector().updateUser(userId, user, osiamAccessTokenProvider.createAccessToken()); // } // // public User searchUserByUserNameAndPassword(String userName, String hashedPassword) { // Query query = new QueryBuilder().filter("userName eq \"" + userName + "\"" // + " and password eq \"" + hashedPassword + "\"").build(); // // SCIMSearchResult<User> result = createOsiamConnector().searchUsers( // query, osiamAccessTokenProvider.createAccessToken() // ); // // if (result.getTotalResults() != 1) { // return null; // } else { // return result.getResources().get(0); // } // } // // private OsiamConnector createOsiamConnector() { // return new OsiamConnector.Builder() // .setAuthServerEndpoint(authServerHome) // .setResourceServerEndpoint(resourceServerHome) // .setClientId(OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID) // .setClientSecret(authServerClientProvider.getClientSecret()) // .withReadTimeout(readTimeout) // .withConnectTimeout(connectTimeout) // .build(); // } // }
import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.osiam.auth.login.ResourceServerConnector; import org.osiam.resources.scim.Role; import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationListener; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.DisabledException; import org.springframework.security.authentication.LockedException; import org.springframework.security.authentication.encoding.ShaPasswordEncoder; import org.springframework.security.authentication.event.AbstractAuthenticationEvent; import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; import org.springframework.security.authentication.event.AuthenticationSuccessEvent; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.springframework.stereotype.Component;
/* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login.internal; @Component public class InternalAuthenticationProvider implements AuthenticationProvider, ApplicationListener<AbstractAuthenticationEvent> { @Value("${org.osiam.auth-server.tempLock.count:0}") private Integer maxLoginFailures; @Value("${org.osiam.auth-server.tempLock.timeout:0}") private Integer lockTimeout; private final Map<String, Integer> accessCounter = Collections.synchronizedMap(new HashMap<String, Integer>()); private final Map<String, Date> lastFailedLogin = Collections.synchronizedMap(new HashMap<String, Date>()); @Autowired
// Path: src/main/java/org/osiam/auth/login/ResourceServerConnector.java // @Service // public class ResourceServerConnector implements InitializingBean{ // // @Value("${org.osiam.resource-server.home}") // private String resourceServerHome; // // @Value("${org.osiam.auth-server.home}") // private String authServerHome; // // @Value("${org.osiam.resource-server.connector.max-connections:40}") // private int maxConnections; // // @Value("${org.osiam.resource-server.connector.read-timeout-ms:10000}") // private int readTimeout; // // @Value("${org.osiam.resource-server.connector.connect-timeout-ms:5000}") // private int connectTimeout; // // @Autowired // private OsiamAccessTokenProvider osiamAccessTokenProvider; // // @Autowired // private OsiamAuthServerClientProvider authServerClientProvider; // // @Override // public void afterPropertiesSet() throws Exception { // OsiamConnector.setMaxConnections(maxConnections); // OsiamConnector.setMaxConnectionsPerRoute(maxConnections); // } // // public User getUserByUsername(final String userName) { // Query query = new QueryBuilder().filter("userName eq \"" + userName + "\"").build(); // // SCIMSearchResult<User> result = createOsiamConnector().searchUsers(query, // osiamAccessTokenProvider.createAccessToken()); // // if (result.getTotalResults() != 1) { // return null; // } else { // return result.getResources().get(0); // } // } // // public User getUserById(final String id) { // return createOsiamConnector().getUser(id, osiamAccessTokenProvider.createAccessToken()); // } // // public User createUser(User user) { // return createOsiamConnector().createUser(user, osiamAccessTokenProvider.createAccessToken()); // } // // public User updateUser(String userId, UpdateUser user) { // return createOsiamConnector().updateUser(userId, user, osiamAccessTokenProvider.createAccessToken()); // } // // public User searchUserByUserNameAndPassword(String userName, String hashedPassword) { // Query query = new QueryBuilder().filter("userName eq \"" + userName + "\"" // + " and password eq \"" + hashedPassword + "\"").build(); // // SCIMSearchResult<User> result = createOsiamConnector().searchUsers( // query, osiamAccessTokenProvider.createAccessToken() // ); // // if (result.getTotalResults() != 1) { // return null; // } else { // return result.getResources().get(0); // } // } // // private OsiamConnector createOsiamConnector() { // return new OsiamConnector.Builder() // .setAuthServerEndpoint(authServerHome) // .setResourceServerEndpoint(resourceServerHome) // .setClientId(OsiamAuthServerClientProvider.AUTH_SERVER_CLIENT_ID) // .setClientSecret(authServerClientProvider.getClientSecret()) // .withReadTimeout(readTimeout) // .withConnectTimeout(connectTimeout) // .build(); // } // } // Path: src/main/java/org/osiam/auth/login/internal/InternalAuthenticationProvider.java import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.osiam.auth.login.ResourceServerConnector; import org.osiam.resources.scim.Role; import org.osiam.resources.scim.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationListener; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.DisabledException; import org.springframework.security.authentication.LockedException; import org.springframework.security.authentication.encoding.ShaPasswordEncoder; import org.springframework.security.authentication.event.AbstractAuthenticationEvent; import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; import org.springframework.security.authentication.event.AuthenticationSuccessEvent; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import org.springframework.stereotype.Component; /* * Copyright (C) 2013 tarent AG * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.osiam.auth.login.internal; @Component public class InternalAuthenticationProvider implements AuthenticationProvider, ApplicationListener<AbstractAuthenticationEvent> { @Value("${org.osiam.auth-server.tempLock.count:0}") private Integer maxLoginFailures; @Value("${org.osiam.auth-server.tempLock.timeout:0}") private Integer lockTimeout; private final Map<String, Integer> accessCounter = Collections.synchronizedMap(new HashMap<String, Integer>()); private final Map<String, Date> lastFailedLogin = Collections.synchronizedMap(new HashMap<String, Date>()); @Autowired
private ResourceServerConnector resourceServerConnector;