001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.analysis.module;
017
018import org.androidtransfuse.adapter.ASTAnnotation;
019import org.androidtransfuse.adapter.ASTType;
020import org.androidtransfuse.analysis.repository.InjectionNodeBuilderRepository;
021import org.androidtransfuse.annotations.ProtectionLevel;
022import org.androidtransfuse.model.manifest.Permission;
023import org.androidtransfuse.processor.ManifestManager;
024
025import javax.inject.Inject;
026
027/**
028 * @author John Ericksen
029 */
030public class PermissionProcessor implements TypeProcessor {
031
032    private final ManifestManager manifestManager;
033
034    @Inject
035    public PermissionProcessor(ManifestManager manifestManager) {
036        this.manifestManager = manifestManager;
037    }
038
039    @Override
040    public ModuleConfiguration process(ASTType moduleType, ASTAnnotation permissionAnnotation) {
041        Permission permission = new Permission();
042        permission.setName(permissionAnnotation.getProperty("name", String.class));
043        permission.setDescription(permissionAnnotation.getProperty("description", String.class));
044        permission.setIcon(permissionAnnotation.getProperty("icon", String.class));
045        permission.setLabel(permissionAnnotation.getProperty("label", String.class));
046        permission.setPermissionGroup(permissionAnnotation.getProperty("permissionGroup", String.class));
047        permission.setProtectionLevel(permissionAnnotation.getProperty("protectionLevel", ProtectionLevel.class));
048
049        return new PermissionModuleConfiguration(permission);
050    }
051
052    private final class PermissionModuleConfiguration implements ModuleConfiguration{
053
054        private final Permission permission;
055
056        private PermissionModuleConfiguration(Permission permission) {
057            this.permission = permission;
058        }
059
060
061        @Override
062        public void setConfiguration(InjectionNodeBuilderRepository configurationRepository) {
063            manifestManager.addPermission(permission);
064        }
065    }
066}