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.model.manifest;
017
018import org.androidtransfuse.model.Identified;
019import org.androidtransfuse.model.Mergeable;
020import org.androidtransfuse.processor.Merge;
021import org.androidtransfuse.processor.MergeCollection;
022
023import javax.xml.bind.annotation.XmlAttribute;
024import javax.xml.bind.annotation.XmlElement;
025import javax.xml.bind.annotation.XmlTransient;
026import java.util.ArrayList;
027import java.util.List;
028
029/**
030 * attributes:
031 * android:enabled=["true" | "false"]
032 * android:exported=["true" | "false"]
033 * android:icon="drawable resource"
034 * android:label="string resource"
035 * android:name="string"
036 * android:permission="string"
037 * android:process="string"
038 * <p/>
039 * can contain:
040 * <intent-filter>
041 * <meta-data>
042 *
043 * @author John Ericksen
044 */
045public class Service extends Mergeable implements Identified {
046
047    private Boolean enabled;
048    private Boolean exported;
049    private String icon;
050    private String label;
051    private String name;
052    private String permission;
053    private String process;
054    private List<IntentFilter> intentFilters = new ArrayList<IntentFilter>();
055    private List<MetaData> metaData = new ArrayList<MetaData>();
056
057    @Merge("e")
058    @XmlAttribute(name = "enabled", namespace = ManifestNamespaceMapper.ANDROID_URI)
059    public Boolean getEnabled() {
060        return enabled;
061    }
062
063    public void setEnabled(Boolean enabled) {
064        this.enabled = enabled;
065    }
066
067    @Merge("x")
068    @XmlAttribute(name = "exported", namespace = ManifestNamespaceMapper.ANDROID_URI)
069    public Boolean getExported() {
070        return exported;
071    }
072
073    public void setExported(Boolean exported) {
074        this.exported = exported;
075    }
076
077    @Merge("i")
078    @XmlAttribute(name = "icon", namespace = ManifestNamespaceMapper.ANDROID_URI)
079    public String getIcon() {
080        return icon;
081    }
082
083    public void setIcon(String icon) {
084        this.icon = icon;
085    }
086
087    @Merge("l")
088    @XmlAttribute(name = "label", namespace = ManifestNamespaceMapper.ANDROID_URI)
089    public String getLabel() {
090        return label;
091    }
092
093    public void setLabel(String label) {
094        this.label = label;
095    }
096
097    @Merge("n")
098    @XmlAttribute(name = "name", namespace = ManifestNamespaceMapper.ANDROID_URI)
099    public String getName() {
100        return name;
101    }
102
103    public void setName(String name) {
104        this.name = name;
105    }
106
107    @Merge("p")
108    @XmlAttribute(name = "permission", namespace = ManifestNamespaceMapper.ANDROID_URI)
109    public String getPermission() {
110        return permission;
111    }
112
113    public void setPermission(String permission) {
114        this.permission = permission;
115    }
116
117    @Merge("r")
118    @XmlAttribute(name = "process", namespace = ManifestNamespaceMapper.ANDROID_URI)
119    public String getProcess() {
120        return process;
121    }
122
123    public void setProcess(String process) {
124        this.process = process;
125    }
126
127    @MergeCollection(collectionType = ArrayList.class, type = IntentFilter.class)
128    @XmlElement(name = "intent-filter")
129    public List<IntentFilter> getIntentFilters() {
130        return intentFilters;
131    }
132
133    public void setIntentFilters(List<IntentFilter> intentFilters) {
134        this.intentFilters = intentFilters;
135    }
136
137    @MergeCollection(collectionType = ArrayList.class, type = MetaData.class)
138    @XmlElement(name = "meta-data")
139    public List<MetaData> getMetaData() {
140        return metaData;
141    }
142
143    public void setMetaData(List<MetaData> metaData) {
144        this.metaData = metaData;
145    }
146
147    @Override
148    @XmlTransient
149    public String getIdentifier() {
150        return name;
151    }
152
153    public void updatePackage(String manifestPackage){
154        if(name != null && name.startsWith(manifestPackage) && containsTag("n")){
155            name = name.substring(manifestPackage.length());
156        }
157    }
158}