KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > cfg > Compilation


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.dev.cfg;
17
18 import com.google.gwt.core.ext.UnableToCompleteException;
19 import com.google.gwt.dev.util.Util;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Represents a single completed compilation.
26  *
27  * @see Compilations
28  */

29 public class Compilation {
30
31   private Map JavaDoc rebindDecisions = new HashMap JavaDoc();
32
33   private Map JavaDoc sourceHashByGeneratedTypeName = new HashMap JavaDoc();
34
35   private String JavaDoc strongName;
36
37   public Compilation() {
38   }
39
40   public String JavaDoc[] getGeneratedTypeNames() {
41     return Util.toStringArray(sourceHashByGeneratedTypeName.keySet());
42   }
43
44   public String JavaDoc[] getRebindInputs() {
45     return Util.toStringArray(rebindDecisions.keySet());
46   }
47
48   /**
49    * @return <code>null</code> if there is no answer for this cached
50    * compilation
51    */

52   public String JavaDoc getRebindOutput(String JavaDoc inputTypeName) {
53     String JavaDoc out = (String JavaDoc) rebindDecisions.get(inputTypeName);
54     return out;
55   }
56
57   public String JavaDoc getStrongName() {
58     return strongName;
59   }
60
61   public String JavaDoc getTypeHash(String JavaDoc generatedTypeName)
62       throws UnableToCompleteException {
63     String JavaDoc hash = (String JavaDoc) sourceHashByGeneratedTypeName.get(generatedTypeName);
64     if (hash != null) {
65       return hash;
66     } else {
67       throw new UnableToCompleteException();
68     }
69   }
70
71   public boolean recordDecision(String JavaDoc inputTypeName, String JavaDoc outputTypeName) {
72     // see if we've already recorded this one
73
String JavaDoc recodedOutputName = (String JavaDoc) rebindDecisions.get(inputTypeName);
74     if (recodedOutputName != null) {
75       // Error to try to change the existing mapping
76
if (!recodedOutputName.equals(outputTypeName)) {
77         String JavaDoc msg = "Decision '" + recodedOutputName
78             + "' already recorded for '" + inputTypeName + "'";
79         throw new IllegalStateException JavaDoc(msg);
80       }
81       // already recorded this one
82
return false;
83     }
84     rebindDecisions.put(inputTypeName, outputTypeName);
85     // this was a new entry
86
return true;
87   }
88
89   public void recordGeneratedTypeHash(String JavaDoc generatedTypeName,
90       String JavaDoc sourceHash) {
91     sourceHashByGeneratedTypeName.put(generatedTypeName, sourceHash);
92   }
93
94   public void setStrongName(String JavaDoc strongName) {
95     this.strongName = strongName;
96   }
97 }
98
Popular Tags