Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

CopierFacade.java

Go to the documentation of this file.
00001 
00058 package com.arcle.rmt.j2se.bridge.copy;
00059 
00060 import java.lang.ref.SoftReference;
00061 import java.util.Map;
00062 import java.util.Hashtable;
00063 
00064 import com.arcle.rmt.rqml.*;
00065 import com.arcle.rmt.j2se.bridge.copy.rqml.*;
00066 import com.arcle.rmt.j2se.util.GenericClassMap;
00067 import com.arcle.rmt.j2se.util.ClassMapVisitor;
00068 import com.arcle.rmt.xplat.util.MutableBoolean;
00069 
00079 public final class CopierFacade implements RQMLSecondClassCopier, ChildCopier {
00080 
00084     private CopierFacade() {  }
00085 
00086 
00087     //-----------------------------------------------------------------------
00088     // Interface implementations
00089 
00099     public boolean copy(final RQMLSecondClass source,
00100             final RQMLSecondClass destination) {
00101         final MutableBoolean copied = new MutableBoolean(false);
00102         ClassMapVisitor visitor = new ClassMapVisitor() {
00103             public boolean visitClassMap(Class cls, Object obj) {
00104                 RQMLSecondClassCopier copier = (RQMLSecondClassCopier) obj;
00105                 copied.value = copier.copy(source, destination);
00106                 // when copy returns true, stop visiting.
00107                 return !copied.value;
00108             }
00109         };
00110         getCopierMap().visitClasses(visitor);
00111         return copied.value;
00112     }
00113 
00130     public boolean copy(Class cls, RQMLSecondClass source,
00131             RQMLSecondClass destination) {
00132         if (!cls.isInterface()) {
00133             throw new IllegalArgumentException("Argument 'cls' is not an interface.");
00134         } else if (!(cls.isInstance(source) && cls.isInstance(destination)) ) {
00135             throw new IllegalArgumentException(
00136                 "Instances of 'source' and 'destination' does not agree or they are not an instance of '" + cls + "'." );
00137         }
00138         RQMLSecondClassCopier copier = (RQMLSecondClassCopier) getCopierMap()
00139             .getMappedObject(cls);
00140         if (copier == null) {
00141             throw new IllegalStateException("Copier not found for class: " + cls);
00142         }
00143 
00144         return copier.copy(source, destination);
00145     }
00146 
00147 
00148     //-----------------------------------------------------------------------
00149     // Accessor Methods
00150 
00151     protected synchronized CopierMap getCopierMap() {
00152         CopierMap cm = (CopierMap) _copiers.get();
00153         if (cm == null) {
00154             cm = createCopierMap();
00155             _copiers = new SoftReference(cm);
00156         }
00157         return cm;
00158     }
00159 
00163     public synchronized static CopierFacade getInstance() {
00164         if (_instance == null) {
00165             _instance = new CopierFacade();
00166         }
00167         return _instance;
00168     }
00169 
00170 
00171     //-----------------------------------------------------------------------
00172     // Factory Methods
00173 
00177     protected CopierMap createCopierMap() {
00178         return new CopierMap();
00179     }
00180 
00181 
00182     //-----------------------------------------------------------------------
00183 
00184 
00191     private SoftReference _copiers = new SoftReference(null);
00192 
00196     private static CopierFacade _instance = null;
00197 
00198     //-----------------------------------------------------------------------
00199     // Inner classes
00200 
00205     protected class CopierMap extends GenericClassMap {
00209         protected Map createMappings() {
00210             ChildCopier cc = CopierFacade.this;
00211             // set capacity to 39 objects, no rehash.
00212             Map copiers = new Hashtable(39, 1);
00213 
00214             //--- First-class objects
00215             copiers.put(Requirement.class, new RequirementCopy(cc));
00216             copiers.put(Stakeholder.class, new StakeholderCopy(cc));
00217             copiers.put(Assumption.class, new AssumptionCopy(cc));
00218             copiers.put(Issue.class, new IssueCopy(cc));
00219             copiers.put(Lexicon.class, new LexiconCopy(cc));
00220             copiers.put(Context.class, new ContextCopy(cc));
00221             copiers.put(Taxonomy.class, new TaxonomyCopy(cc));
00222             copiers.put(Project.class, new ProjectCopy(cc));
00223             copiers.put(Usecase.class, new UsecaseCopy(cc));
00224 
00225             //--- Second-class objects
00226             copiers.put(Name.class, new NameCopy(cc));
00227             copiers.put(Description.class, new DescriptionCopy(cc));
00228             copiers.put(Rationale.class, new RationaleCopy(cc));
00229             copiers.put(Definition.class, new DefinitionCopy(cc));
00230             copiers.put(Origin.class, new OriginCopy(cc));
00231             copiers.put(TextualData.class, new TextualDataCopy(cc));
00232             copiers.put(Product.class, new ProductCopy(cc));
00233             copiers.put(Problem.class, new ProblemCopy(cc));
00234             copiers.put(Scope.class, new ScopeCopy(cc));
00235             copiers.put(Vision.class, new VisionCopy(cc));
00236 
00237             copiers.put(Actor.class, new ActorCopy(cc));
00238             copiers.put(Precondition.class, new PreconditionCopy(cc));
00239             copiers.put(Postcondition.class, new PostconditionCopy(cc));
00240             copiers.put(NormalCourse.class, new NormalCourseCopy(cc));
00241             copiers.put(AlternativeCourse.class, new AlternativeCourseCopy(cc));
00242             copiers.put(com.arcle.rmt.rqml.Exception.class, new ExceptionCopy(cc));
00243             copiers.put(Comment.class, new CommentCopy(cc));
00244 
00245             copiers.put(ActorAction.class, new ActorActionCopy(cc));
00246             copiers.put(SystemResponse.class, new SystemResponseCopy(cc));
00247 
00248             return copiers;
00249         }
00250     }
00251 }

Generated on Fri Jun 18 19:51:14 2004 for Arcle Rambutan by doxygen 1.3.5