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; 017 018import org.androidtransfuse.model.manifest.ManifestBase; 019import org.androidtransfuse.model.manifest.ManifestNamespaceMapper; 020import org.androidtransfuse.processor.MergeableTagConverter; 021import org.androidtransfuse.processor.MergeableTags; 022 023import javax.xml.bind.annotation.XmlAttribute; 024import javax.xml.bind.annotation.XmlTransient; 025import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 026 027/** 028 * @author John Ericksen 029 */ 030public class Mergeable extends ManifestBase { 031 032 private static final String GENERATED_TOKEN = "+"; 033 034 private MergeableTags tags = new MergeableTags(); 035 036 @XmlAttribute(name = "tag", namespace = ManifestNamespaceMapper.TRANSFUSE_URI) 037 @XmlJavaTypeAdapter(MergeableTagConverter.class) 038 public MergeableTags getTags() { 039 return tags; 040 } 041 042 public void setTags(MergeableTags tags) { 043 this.tags = tags; 044 } 045 046 @XmlTransient 047 public int getMergeTagSize(){ 048 if(tags != null){ 049 return tags.getTags().size(); 050 } 051 return 0; 052 } 053 054 public void addMergeTag(String tag) { 055 tags.getTags().add(tag); 056 } 057 058 public boolean containsTag(String tag) { 059 return tags != null && tags.getTags().contains(tag); 060 } 061 062 public void removeMergeTag(String tag) { 063 if(tags != null){ 064 tags.getTags().remove(tag); 065 } 066 } 067 068 @XmlTransient 069 public boolean isGenerated(){ 070 return containsTag(GENERATED_TOKEN); 071 } 072 073 public synchronized void setGenerated(boolean generated) { 074 if(tags == null){ 075 tags = new MergeableTags(); 076 } 077 this.tags.getTags().add(GENERATED_TOKEN); 078 } 079}